@@ -14,12 +14,12 @@ def test_group_by_copy():
1414 ).set_index ("name" )
1515
1616 msg = "DataFrameGroupBy.apply operated on the grouping columns"
17- with tm .assert_produces_warning (FutureWarning , match = msg ):
17+ with tm .assert_produces_warning (DeprecationWarning , match = msg ):
1818 grp_by_same_value = df .groupby (["age" ], group_keys = False ).apply (
1919 lambda group : group
2020 )
2121 msg = "DataFrameGroupBy.apply operated on the grouping columns"
22- with tm .assert_produces_warning (FutureWarning , match = msg ):
22+ with tm .assert_produces_warning (DeprecationWarning , match = msg ):
2323 grp_by_copy = df .groupby (["age" ], group_keys = False ).apply (
2424 lambda group : group .copy ()
2525 )
@@ -54,9 +54,9 @@ def f_no_copy(x):
5454 return x .groupby ("cat2" )["rank" ].min ()
5555
5656 msg = "DataFrameGroupBy.apply operated on the grouping columns"
57- with tm .assert_produces_warning (FutureWarning , match = msg ):
57+ with tm .assert_produces_warning (DeprecationWarning , match = msg ):
5858 grpby_copy = df .groupby ("cat1" ).apply (f_copy )
59- with tm .assert_produces_warning (FutureWarning , match = msg ):
59+ with tm .assert_produces_warning (DeprecationWarning , match = msg ):
6060 grpby_no_copy = df .groupby ("cat1" ).apply (f_no_copy )
6161 tm .assert_series_equal (grpby_copy , grpby_no_copy )
6262
@@ -68,14 +68,14 @@ def test_no_mutate_but_looks_like():
6868 df = pd .DataFrame ({"key" : [1 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 3 ], "value" : range (9 )})
6969
7070 msg = "DataFrameGroupBy.apply operated on the grouping columns"
71- with tm .assert_produces_warning (FutureWarning , match = msg ):
71+ with tm .assert_produces_warning (DeprecationWarning , match = msg ):
7272 result1 = df .groupby ("key" , group_keys = True ).apply (lambda x : x [:].key )
73- with tm .assert_produces_warning (FutureWarning , match = msg ):
73+ with tm .assert_produces_warning (DeprecationWarning , match = msg ):
7474 result2 = df .groupby ("key" , group_keys = True ).apply (lambda x : x .key )
7575 tm .assert_series_equal (result1 , result2 )
7676
7777
78- def test_apply_function_with_indexing ():
78+ def test_apply_function_with_indexing (warn_copy_on_write ):
7979 # GH: 33058
8080 df = pd .DataFrame (
8181 {"col1" : ["A" , "A" , "A" , "B" , "B" , "B" ], "col2" : [1 , 2 , 3 , 4 , 5 , 6 ]}
@@ -86,7 +86,9 @@ def fn(x):
8686 return x .col2
8787
8888 msg = "DataFrameGroupBy.apply operated on the grouping columns"
89- with tm .assert_produces_warning (FutureWarning , match = msg ):
89+ with tm .assert_produces_warning (
90+ DeprecationWarning , match = msg , raise_on_extra_warnings = not warn_copy_on_write
91+ ):
9092 result = df .groupby (["col1" ], as_index = False ).apply (fn )
9193 expected = pd .Series (
9294 [1 , 2 , 0 , 4 , 5 , 0 ],
0 commit comments