@@ -14,12 +14,12 @@ def test_group_by_copy():
14
14
).set_index ("name" )
15
15
16
16
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 ):
18
18
grp_by_same_value = df .groupby (["age" ], group_keys = False ).apply (
19
19
lambda group : group
20
20
)
21
21
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 ):
23
23
grp_by_copy = df .groupby (["age" ], group_keys = False ).apply (
24
24
lambda group : group .copy ()
25
25
)
@@ -54,9 +54,9 @@ def f_no_copy(x):
54
54
return x .groupby ("cat2" )["rank" ].min ()
55
55
56
56
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 ):
58
58
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 ):
60
60
grpby_no_copy = df .groupby ("cat1" ).apply (f_no_copy )
61
61
tm .assert_series_equal (grpby_copy , grpby_no_copy )
62
62
@@ -68,14 +68,14 @@ def test_no_mutate_but_looks_like():
68
68
df = pd .DataFrame ({"key" : [1 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 3 ], "value" : range (9 )})
69
69
70
70
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 ):
72
72
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 ):
74
74
result2 = df .groupby ("key" , group_keys = True ).apply (lambda x : x .key )
75
75
tm .assert_series_equal (result1 , result2 )
76
76
77
77
78
- def test_apply_function_with_indexing ():
78
+ def test_apply_function_with_indexing (warn_copy_on_write ):
79
79
# GH: 33058
80
80
df = pd .DataFrame (
81
81
{"col1" : ["A" , "A" , "A" , "B" , "B" , "B" ], "col2" : [1 , 2 , 3 , 4 , 5 , 6 ]}
@@ -86,7 +86,9 @@ def fn(x):
86
86
return x .col2
87
87
88
88
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
+ ):
90
92
result = df .groupby (["col1" ], as_index = False ).apply (fn )
91
93
expected = pd .Series (
92
94
[1 , 2 , 0 , 4 , 5 , 0 ],
0 commit comments