diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 0ef5636a97d40..f6c729959aec1 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -505,6 +505,7 @@ Other API changes Deprecations ~~~~~~~~~~~~ - Deprecated argument ``infer_datetime_format`` in :func:`to_datetime` and :func:`read_csv`, as a strict version of it is now the default (:issue:`48621`) +- Deprecate unused argument ``**kwargs`` from :meth:`cummax`, :meth:`cummin`, :meth:`cumsum`, :meth:`cumprod`, :meth:`take` and :meth:`skew` (:issue:`50483`) .. --------------------------------------------------------------------------- diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 955f65585963d..eb030bf3afc44 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -48,6 +48,7 @@ from pandas.util._decorators import ( Appender, Substitution, + deprecate_nonkeyword_arguments, doc, ) @@ -893,6 +894,9 @@ def fillna( return result @doc(Series.take.__doc__) + @deprecate_nonkeyword_arguments( + version="3.0", allowed_args=["self", "axis", "indices"] + ) def take( self, indices: TakeIndexer, @@ -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, @@ -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 @@ -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, @@ -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 diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 729f34544e2bc..7b810b4b65602 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -69,6 +69,7 @@ class providing the base-class of operations. Appender, Substitution, cache_readonly, + deprecate_nonkeyword_arguments, doc, ) @@ -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. @@ -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. @@ -3447,6 +3450,9 @@ def cumsum(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", "numeric_only"] + ) def cummin( self, axis: AxisInt = 0, numeric_only: bool = False, **kwargs ) -> NDFrameT: @@ -3472,6 +3478,9 @@ def cummin( @final @Substitution(name="groupby") @Appender(_common_see_also) + @deprecate_nonkeyword_arguments( + version="3.0", allowed_args=["self", "axis", "numeric_only"] + ) def cummax( self, axis: AxisInt = 0, numeric_only: bool = False, **kwargs ) -> NDFrameT: diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index bb15783f4607f..2f9cfceb000e6 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -1594,3 +1594,19 @@ def test_multiindex_group_all_columns_when_empty(groupby_func): result = method(*args).index expected = df.index tm.assert_index_equal(result, expected) + + +def test_deprecated_keywords(): + msg = ( + "In the future version of pandas the arguments args" + "and kwargs will be deprecated for these functions" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + df = DataFrame({"a": [1, 1, 2], "b": [3, 4, 5]}) + gb = df.groupby("a") + assert gb.cummax(kwargs=1) + assert gb.cummin(kwargs=1) + assert gb.cumsum(args=1, kwargs=1) + assert gb.cumprod(args=1, kwargs=1) + assert gb.skew(kwargs=1) + assert gb.take(kwargs=1)