Skip to content

Commit b962025

Browse files
committed
DEPR fill_method and limit keywords in GroupBy pct_change
1 parent dea36ba commit b962025

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

pandas/core/groupby/groupby.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3945,8 +3945,8 @@ def diff(
39453945
def pct_change(
39463946
self,
39473947
periods: int = 1,
3948-
fill_method: FillnaOptions = "ffill",
3949-
limit: int | None = None,
3948+
fill_method: FillnaOptions | lib.NoDefault = lib.no_default,
3949+
limit: int | None | lib.NoDefault = lib.no_default,
39503950
freq=None,
39513951
axis: Axis | lib.NoDefault = lib.no_default,
39523952
):
@@ -3958,6 +3958,21 @@ def pct_change(
39583958
Series or DataFrame
39593959
Percentage changes within each group.
39603960
"""
3961+
if fill_method is not lib.no_default or limit is not lib.no_default:
3962+
# GH#53491
3963+
warnings.warn(
3964+
"The 'fill_method' and 'limit' keywords in "
3965+
f"{type(self).__name__}.pct_change are deprecated and will be "
3966+
"removed in a future version. Call fillna directly before "
3967+
"calling pct_change instead.",
3968+
FutureWarning,
3969+
stacklevel=find_stack_level(),
3970+
)
3971+
if fill_method is lib.no_default:
3972+
fill_method = "ffill"
3973+
if limit is lib.no_default:
3974+
limit = None
3975+
39613976
if axis is not lib.no_default:
39623977
axis = self.obj._get_axis_number(axis)
39633978
self._deprecate_axis(axis, "pct_change")

pandas/tests/groupby/transform/test_transform.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,9 +969,14 @@ def test_pct_change(frame_or_series, freq, periods, fill_method, limit):
969969
else:
970970
expected = expected.to_frame("vals")
971971

972-
result = gb.pct_change(
973-
periods=periods, fill_method=fill_method, limit=limit, freq=freq
972+
msg = (
973+
"The 'fill_method' and 'limit' keywords in "
974+
f"{type(gb).__name__}.pct_change are deprecated"
974975
)
976+
with tm.assert_produces_warning(FutureWarning, match=msg):
977+
result = gb.pct_change(
978+
periods=periods, fill_method=fill_method, limit=limit, freq=freq
979+
)
975980
tm.assert_equal(result, expected)
976981

977982

0 commit comments

Comments
 (0)