Skip to content

Commit 67049ea

Browse files
committed
DEPR: Update groupby.apply DeprecationWarning to FutureWarning
1 parent dc47602 commit 67049ea

21 files changed

+150
-150
lines changed

pandas/core/groupby/groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,7 @@ def f(g):
18311831
message=_apply_groupings_depr.format(
18321832
type(self).__name__, "apply"
18331833
),
1834-
category=DeprecationWarning,
1834+
category=FutureWarning,
18351835
stacklevel=find_stack_level(),
18361836
)
18371837
except TypeError:

pandas/core/resample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2913,7 +2913,7 @@ def _apply(
29132913
new_message = _apply_groupings_depr.format("DataFrameGroupBy", "resample")
29142914
with rewrite_warning(
29152915
target_message=target_message,
2916-
target_category=DeprecationWarning,
2916+
target_category=FutureWarning,
29172917
new_message=new_message,
29182918
):
29192919
result = grouped.apply(how, *args, include_groups=include_groups, **kwargs)

pandas/tests/extension/base/groupby.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ def test_groupby_extension_transform(self, data_for_grouping):
114114
def test_groupby_extension_apply(self, data_for_grouping, groupby_apply_op):
115115
df = pd.DataFrame({"A": [1, 1, 2, 2, 3, 3, 1, 4], "B": data_for_grouping})
116116
msg = "DataFrameGroupBy.apply operated on the grouping columns"
117-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
117+
with tm.assert_produces_warning(FutureWarning, match=msg):
118118
df.groupby("B", group_keys=False, observed=False).apply(groupby_apply_op)
119119
df.groupby("B", group_keys=False, observed=False).A.apply(groupby_apply_op)
120120
msg = "DataFrameGroupBy.apply operated on the grouping columns"
121-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
121+
with tm.assert_produces_warning(FutureWarning, match=msg):
122122
df.groupby("A", group_keys=False, observed=False).apply(groupby_apply_op)
123123
df.groupby("A", group_keys=False, observed=False).B.apply(groupby_apply_op)
124124

pandas/tests/frame/test_stack_unstack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ def test_unstack_bug(self, future_stack):
18251825
)
18261826

18271827
msg = "DataFrameGroupBy.apply operated on the grouping columns"
1828-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
1828+
with tm.assert_produces_warning(FutureWarning, match=msg):
18291829
result = df.groupby(["state", "exp", "barcode", "v"]).apply(len)
18301830

18311831
unstacked = result.unstack()

pandas/tests/groupby/aggregate/test_other.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,15 +502,15 @@ def test_agg_timezone_round_trip():
502502

503503
# GH#27110 applying iloc should return a DataFrame
504504
msg = "DataFrameGroupBy.apply operated on the grouping columns"
505-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
505+
with tm.assert_produces_warning(FutureWarning, match=msg):
506506
assert ts == grouped.apply(lambda x: x.iloc[0]).iloc[0, 1]
507507

508508
ts = df["B"].iloc[2]
509509
assert ts == grouped.last()["B"].iloc[0]
510510

511511
# GH#27110 applying iloc should return a DataFrame
512512
msg = "DataFrameGroupBy.apply operated on the grouping columns"
513-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
513+
with tm.assert_produces_warning(FutureWarning, match=msg):
514514
assert ts == grouped.apply(lambda x: x.iloc[-1]).iloc[0, 1]
515515

516516

pandas/tests/groupby/methods/test_value_counts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def test_against_frame_and_seriesgroupby(
330330
)
331331
if frame:
332332
# compare against apply with DataFrame value_counts
333-
warn = DeprecationWarning if groupby == "column" else None
333+
warn = FutureWarning if groupby == "column" else None
334334
msg = "DataFrameGroupBy.apply operated on the grouping columns"
335335
with tm.assert_produces_warning(warn, match=msg):
336336
expected = gp.apply(

pandas/tests/groupby/test_apply.py

Lines changed: 63 additions & 63 deletions
Large diffs are not rendered by default.

pandas/tests/groupby/test_apply_mutate.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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(DeprecationWarning, match=msg):
17+
with tm.assert_produces_warning(FutureWarning, 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(DeprecationWarning, match=msg):
22+
with tm.assert_produces_warning(FutureWarning, 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(DeprecationWarning, match=msg):
57+
with tm.assert_produces_warning(FutureWarning, match=msg):
5858
grpby_copy = df.groupby("cat1").apply(f_copy)
59-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
59+
with tm.assert_produces_warning(FutureWarning, 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,9 +68,9 @@ 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(DeprecationWarning, match=msg):
71+
with tm.assert_produces_warning(FutureWarning, match=msg):
7272
result1 = df.groupby("key", group_keys=True).apply(lambda x: x[:].key)
73-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
73+
with tm.assert_produces_warning(FutureWarning, match=msg):
7474
result2 = df.groupby("key", group_keys=True).apply(lambda x: x.key)
7575
tm.assert_series_equal(result1, result2)
7676

@@ -87,7 +87,7 @@ def fn(x):
8787

8888
msg = "DataFrameGroupBy.apply operated on the grouping columns"
8989
with tm.assert_produces_warning(
90-
DeprecationWarning, match=msg, raise_on_extra_warnings=not warn_copy_on_write
90+
FutureWarning, match=msg, raise_on_extra_warnings=not warn_copy_on_write
9191
):
9292
result = df.groupby(["col1"], as_index=False).apply(fn)
9393
expected = pd.Series(

pandas/tests/groupby/test_categorical.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def f(x):
125125
return x.drop_duplicates("person_name").iloc[0]
126126

127127
msg = "DataFrameGroupBy.apply operated on the grouping columns"
128-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
128+
with tm.assert_produces_warning(FutureWarning, match=msg):
129129
result = g.apply(f)
130130
expected = x.iloc[[0, 1]].copy()
131131
expected.index = Index([1, 2], name="person_id")
@@ -333,7 +333,7 @@ def test_apply(ordered):
333333
idx = MultiIndex.from_arrays([missing, dense], names=["missing", "dense"])
334334
expected = Series(1, index=idx)
335335
msg = "DataFrameGroupBy.apply operated on the grouping columns"
336-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
336+
with tm.assert_produces_warning(FutureWarning, match=msg):
337337
result = grouped.apply(lambda x: 1)
338338
tm.assert_series_equal(result, expected)
339339

@@ -2050,7 +2050,7 @@ def test_category_order_apply(as_index, sort, observed, method, index_kind, orde
20502050
df["a2"] = df["a"]
20512051
df = df.set_index(keys)
20522052
gb = df.groupby(keys, as_index=as_index, sort=sort, observed=observed)
2053-
warn = DeprecationWarning if method == "apply" and index_kind == "range" else None
2053+
warn = FutureWarning if method == "apply" and index_kind == "range" else None
20542054
msg = "DataFrameGroupBy.apply operated on the grouping columns"
20552055
with tm.assert_produces_warning(warn, match=msg):
20562056
op_result = getattr(gb, method)(lambda x: x.sum(numeric_only=True))

pandas/tests/groupby/test_counting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def test_count():
290290
for key in ["1st", "2nd", ["1st", "2nd"]]:
291291
left = df.groupby(key).count()
292292
msg = "DataFrameGroupBy.apply operated on the grouping columns"
293-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
293+
with tm.assert_produces_warning(FutureWarning, match=msg):
294294
right = df.groupby(key).apply(DataFrame.count).drop(key, axis=1)
295295
tm.assert_frame_equal(left, right)
296296

0 commit comments

Comments
 (0)