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
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`)
- Deprecate argument ``**kwargs`` from :meth:`cummax`, :meth:`cummin`, :meth:`cumsum`, :meth:`cumprod`, :meth:`take` and :meth:`skew` (:issue:`50483`)
Copy link
Member

Choose a reason for hiding this comment

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

This is currently in the section of deprecations that we are enforcing for 2.0. Instead, it should be in the new deprecations that are introduced in 2.0. That's one section up from this.

Can you add "unused" before "argument" to indicate to users we're not removing any functionality.

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 surely i'll do the changes

-

.. ---------------------------------------------------------------------------
Expand Down
32 changes: 16 additions & 16 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from pandas.util._decorators import (
Appender,
Substitution,
deprecate_nonkeyword_arguments,
doc,
)

Expand Down Expand Up @@ -893,6 +894,9 @@ def fillna(
return result

@doc(Series.take.__doc__)
@deprecate_nonkeyword_arguments(
version="3.0", allowed_args=["self", "axis", "indices"]
)
Copy link
Member

Choose a reason for hiding this comment

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

Having another look, looks like deprecate_nonkeyword_arguments doesn't deprecate the argument, but makes it usable only via a keyword argument (e.g. foo(1) would produce the warning, but foo(val=1) wouldn't). If that's the case, doesn't seem like we've got a decorator to simply deprecate an argument. In that case, you'll have to produce it manually.

def take(
self,
indices: TakeIndexer,
Expand All @@ -903,6 +907,9 @@ def take(
return result

@doc(Series.skew.__doc__)
@deprecate_nonkeyword_arguments(
version="3.0", allowed_args=["self", "axis", "skipna", "numeric_only"]
)
def skew(
self,
axis: Axis | lib.NoDefault = lib.no_default,
Expand All @@ -911,11 +918,7 @@ def skew(
**kwargs,
) -> Series:
result = self._op_via_apply(
"skew",
axis=axis,
skipna=skipna,
numeric_only=numeric_only,
**kwargs,
"skew", axis=axis, skipna=skipna, numeric_only=numeric_only, **kwargs
)
return result

Expand Down Expand Up @@ -2272,16 +2275,17 @@ def fillna(
return result

@doc(DataFrame.take.__doc__)
def take(
self,
indices: TakeIndexer,
axis: Axis | None = 0,
**kwargs,
) -> DataFrame:
@deprecate_nonkeyword_arguments(
version="3.0", allowed_args=["self", "indices", "axis"]
)
def take(self, indices: TakeIndexer, axis: Axis | None = 0, **kwargs) -> DataFrame:
result = self._op_via_apply("take", indices=indices, axis=axis, **kwargs)
return result

@doc(DataFrame.skew.__doc__)
@deprecate_nonkeyword_arguments(
version="3.0", allowed_args=["self", "axis", "skipna", "numeric_only"]
)
def skew(
self,
axis: Axis | None | lib.NoDefault = lib.no_default,
Expand All @@ -2290,11 +2294,7 @@ def skew(
**kwargs,
) -> DataFrame:
result = self._op_via_apply(
"skew",
axis=axis,
skipna=skipna,
numeric_only=numeric_only,
**kwargs,
"skew", axis=axis, skipna=skipna, numeric_only=numeric_only, **kwargs
)
return result

Expand Down
3 changes: 3 additions & 0 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class providing the base-class of operations.
Appender,
Substitution,
cache_readonly,
deprecate_nonkeyword_arguments,
doc,
)

Expand Down Expand Up @@ -3411,6 +3412,7 @@ def rank(
@final
@Substitution(name="groupby")
@Appender(_common_see_also)
@deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self", "axis"])
def cumprod(self, axis: Axis = 0, *args, **kwargs) -> NDFrameT:
"""
Cumulative product for each group.
Expand All @@ -3429,6 +3431,7 @@ def cumprod(self, axis: Axis = 0, *args, **kwargs) -> NDFrameT:
@final
@Substitution(name="groupby")
@Appender(_common_see_also)
@deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self", "axis"])
def cumsum(self, axis: Axis = 0, *args, **kwargs) -> NDFrameT:
"""
Cumulative sum for each group.
Expand Down