Skip to content

DEPR: Remove unnecessary kwargs in groupby ops #50483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ Removal of prior version deprecations/changes
- Removed the deprecated argument ``line_terminator`` from :meth:`DataFrame.to_csv` (:issue:`45302`)
- Removed the deprecated argument ``label`` from :func:`lreshape` (:issue:`30219`)
- Arguments after ``expr`` in :meth:`DataFrame.eval` and :meth:`DataFrame.query` are keyword-only (:issue:`47587`)
- Removed argument ``**kwargs`` from :meth:`cummax`, :meth:`cummin`, :meth:`cumsum`, :meth:`cumprod`, :meth:`take` and :meth:`skew` (:issue:`50483`)
-

.. ---------------------------------------------------------------------------
Expand Down
18 changes: 10 additions & 8 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,9 +897,12 @@ def take(
self,
indices: TakeIndexer,
axis: Axis = 0,
**kwargs,
) -> Series:
result = self._op_via_apply("take", indices=indices, axis=axis, **kwargs)
result = self._op_via_apply(
"take",
indices=indices,
axis=axis,
)
return result

@doc(Series.skew.__doc__)
Expand All @@ -908,14 +911,12 @@ def skew(
axis: Axis | lib.NoDefault = lib.no_default,
skipna: bool = True,
numeric_only: bool = False,
**kwargs,
) -> Series:
result = self._op_via_apply(
"skew",
axis=axis,
skipna=skipna,
numeric_only=numeric_only,
**kwargs,
)
return result

Expand Down Expand Up @@ -2276,9 +2277,12 @@ def take(
self,
indices: TakeIndexer,
axis: Axis | None = 0,
**kwargs,
) -> DataFrame:
result = self._op_via_apply("take", indices=indices, axis=axis, **kwargs)
result = self._op_via_apply(
"take",
indices=indices,
axis=axis,
)
return result

@doc(DataFrame.skew.__doc__)
Expand All @@ -2287,14 +2291,12 @@ def skew(
axis: Axis | None | lib.NoDefault = lib.no_default,
skipna: bool = True,
numeric_only: bool = False,
**kwargs,
) -> DataFrame:
result = self._op_via_apply(
"skew",
axis=axis,
skipna=skipna,
numeric_only=numeric_only,
**kwargs,
)
return result

Expand Down
20 changes: 12 additions & 8 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3411,38 +3411,42 @@ def rank(
@final
@Substitution(name="groupby")
@Appender(_common_see_also)
def cumprod(self, axis: Axis = 0, *args, **kwargs) -> NDFrameT:
def cumprod(self, axis: Axis = 0) -> NDFrameT:
"""
Cumulative product for each group.

Returns
-------
Series or DataFrame
"""
nv.validate_groupby_func("cumprod", args, kwargs, ["numeric_only", "skipna"])
nv.validate_groupby_func("cumprod", (), {}, ["numeric_only", "skipna"])
if axis != 0:
f = lambda x: x.cumprod(axis=axis, **kwargs)
f = lambda x: x.cumprod(
axis=axis,
)
return self._python_apply_general(f, self._selected_obj, is_transform=True)

return self._cython_transform("cumprod", **kwargs)
return self._cython_transform(
"cumprod",
)

@final
@Substitution(name="groupby")
@Appender(_common_see_also)
def cumsum(self, axis: Axis = 0, *args, **kwargs) -> NDFrameT:
def cumsum(self, axis: Axis = 0) -> NDFrameT:
"""
Cumulative sum for each group.

Returns
-------
Series or DataFrame
"""
nv.validate_groupby_func("cumsum", args, kwargs, ["numeric_only", "skipna"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI is failing because of this. You can't simply delete the values, you should provide an empty tuple and an empty dictionary instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes will do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am getting this error Error: The runner has received a shutdown signal...' in GHA. GH 45651 , could you help on this.

nv.validate_groupby_func("cumsum", (), {}, ["numeric_only", "skipna"])
if axis != 0:
f = lambda x: x.cumsum(axis=axis, **kwargs)
f = lambda x: x.cumsum(axis=axis)
return self._python_apply_general(f, self._selected_obj, is_transform=True)

return self._cython_transform("cumsum", **kwargs)
return self._cython_transform("cumsum")

@final
@Substitution(name="groupby")
Expand Down