From 7ebf8227efab052800ce8a5234ab6d2bd573329c Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Thu, 29 Dec 2022 11:20:49 +0530 Subject: [PATCH 01/16] Depr: unnecessary kwargs in groupby ops --- pandas/core/groupby/generic.py | 10 ++-------- pandas/core/groupby/groupby.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 955f65585963d..18ec2fe6c9c15 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -897,9 +897,8 @@ 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__) @@ -908,14 +907,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 @@ -2276,9 +2273,8 @@ 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__) @@ -2287,14 +2283,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 diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 729f34544e2bc..96ee504f40fc8 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -3411,7 +3411,7 @@ 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. @@ -3419,17 +3419,17 @@ def cumprod(self, axis: Axis = 0, *args, **kwargs) -> NDFrameT: ------- 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. @@ -3437,12 +3437,12 @@ def cumsum(self, axis: Axis = 0, *args, **kwargs) -> NDFrameT: ------- Series or DataFrame """ - nv.validate_groupby_func("cumsum", args, kwargs, ["numeric_only", "skipna"]) + 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") From 88ab27068b8c80030ffc05c9356fc39a744e77af Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Thu, 29 Dec 2022 12:00:41 +0530 Subject: [PATCH 02/16] update --- pandas/core/groupby/generic.py | 12 ++++++++++-- pandas/core/groupby/groupby.py | 10 +++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 18ec2fe6c9c15..f5cc3d9983570 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -898,7 +898,11 @@ def take( indices: TakeIndexer, axis: Axis = 0, ) -> Series: - result = self._op_via_apply("take", indices=indices, axis=axis,) + result = self._op_via_apply( + "take", + indices=indices, + axis=axis, + ) return result @doc(Series.skew.__doc__) @@ -2274,7 +2278,11 @@ def take( indices: TakeIndexer, axis: Axis | None = 0, ) -> DataFrame: - result = self._op_via_apply("take", indices=indices, axis=axis,) + result = self._op_via_apply( + "take", + indices=indices, + axis=axis, + ) return result @doc(DataFrame.skew.__doc__) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 96ee504f40fc8..54bcbe07c6b7b 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -3421,10 +3421,14 @@ def cumprod(self, axis: Axis = 0) -> NDFrameT: """ nv.validate_groupby_func("cumprod", ["numeric_only", "skipna"]) if axis != 0: - f = lambda x: x.cumprod(axis=axis,) + f = lambda x: x.cumprod( + axis=axis, + ) return self._python_apply_general(f, self._selected_obj, is_transform=True) - return self._cython_transform("cumprod",) + return self._cython_transform( + "cumprod", + ) @final @Substitution(name="groupby") @@ -3437,7 +3441,7 @@ def cumsum(self, axis: Axis = 0) -> NDFrameT: ------- Series or DataFrame """ - nv.validate_groupby_func("cumsum",["numeric_only", "skipna"]) + nv.validate_groupby_func("cumsum", ["numeric_only", "skipna"]) if axis != 0: f = lambda x: x.cumsum(axis=axis) return self._python_apply_general(f, self._selected_obj, is_transform=True) From aff453dac06ec0c883cacd729cda0eaaccabf0ac Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Thu, 29 Dec 2022 22:47:36 +0530 Subject: [PATCH 03/16] added the whatsnew entey and modified the code --- doc/source/whatsnew/v2.0.0.rst | 1 + pandas/core/groupby/groupby.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 0ef5636a97d40..88311b8d1199c 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -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`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 54bcbe07c6b7b..e0646fb8a247d 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -3419,7 +3419,7 @@ def cumprod(self, axis: Axis = 0) -> NDFrameT: ------- Series or DataFrame """ - nv.validate_groupby_func("cumprod", ["numeric_only", "skipna"]) + nv.validate_groupby_func("cumprod", (), {}, ["numeric_only", "skipna"]) if axis != 0: f = lambda x: x.cumprod( axis=axis, @@ -3441,7 +3441,7 @@ def cumsum(self, axis: Axis = 0) -> NDFrameT: ------- Series or DataFrame """ - nv.validate_groupby_func("cumsum", ["numeric_only", "skipna"]) + nv.validate_groupby_func("cumsum", (), {}, ["numeric_only", "skipna"]) if axis != 0: f = lambda x: x.cumsum(axis=axis) return self._python_apply_general(f, self._selected_obj, is_transform=True) From 4f6548b47bc9324a89fb216834ab6d0c83836a19 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 31 Dec 2022 19:10:25 +0530 Subject: [PATCH 04/16] added the decorator above the functions --- pandas/core/groupby/generic.py | 44 ++++++++++++++++------------------ pandas/core/groupby/groupby.py | 23 +++++++++--------- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index f5cc3d9983570..f83749344e8ea 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -99,6 +99,7 @@ from pandas.core.util.numba_ import maybe_use_numba from pandas.plotting import boxplot_frame_groupby +from pandas.util._decorators import deprecate_nonkeyword_arguments if TYPE_CHECKING: from pandas.core.generic import NDFrame @@ -893,30 +894,31 @@ def fillna( return result @doc(Series.take.__doc__) + @deprecate_nonkeyword_arguments( + verison="3.0", allowed_args=["self", "axis", "indices"] + ) def take( self, indices: TakeIndexer, axis: Axis = 0, + **kwargs, ) -> Series: - result = self._op_via_apply( - "take", - indices=indices, - axis=axis, - ) + result = self._op_via_apply("take", indices=indices, axis=axis, **kwargs) return result @doc(Series.skew.__doc__) + @deprecate_nonkeyword_arguments( + verison="3.0", allowed_args=["self", "axis", "skipna", "numeric_only"] + ) def skew( self, 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, + "skew", axis=axis, skipna=skipna, numeric_only=numeric_only, **kwargs ) return result @@ -2273,30 +2275,26 @@ def fillna( return result @doc(DataFrame.take.__doc__) - def take( - self, - indices: TakeIndexer, - axis: Axis | None = 0, - ) -> DataFrame: - result = self._op_via_apply( - "take", - indices=indices, - axis=axis, - ) + @deprecate_nonkeyword_arguments( + verison="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( + verison="3.0", allowed_args=["self", "axis", "skipna", "numeric_only"] + ) def skew( self, 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, + "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 e0646fb8a247d..3620f90a1a96e 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -70,6 +70,7 @@ class providing the base-class of operations. Substitution, cache_readonly, doc, + deprecate_nonkeyword_arguments, ) from pandas.core.dtypes.cast import ensure_dtype_can_hold_na @@ -3411,7 +3412,8 @@ def rank( @final @Substitution(name="groupby") @Appender(_common_see_also) - def cumprod(self, axis: Axis = 0) -> NDFrameT: + @deprecate_nonkeyword_arguments(verison="3.0", allowed_args=["self", "axis"]) + def cumprod(self, axis: Axis = 0, *args, **kwargs) -> NDFrameT: """ Cumulative product for each group. @@ -3419,21 +3421,18 @@ def cumprod(self, axis: Axis = 0) -> NDFrameT: ------- Series or DataFrame """ - nv.validate_groupby_func("cumprod", (), {}, ["numeric_only", "skipna"]) + nv.validate_groupby_func("cumprod", args, kwargs, ["numeric_only", "skipna"]) if axis != 0: - f = lambda x: x.cumprod( - axis=axis, - ) + f = lambda x: x.cumprod(axis=axis, **kwargs) return self._python_apply_general(f, self._selected_obj, is_transform=True) - return self._cython_transform( - "cumprod", - ) + return self._cython_transform("cumprod", **kwargs) @final @Substitution(name="groupby") @Appender(_common_see_also) - def cumsum(self, axis: Axis = 0) -> NDFrameT: + @deprecate_nonkeyword_arguments(verison="3.0", allowed_args=["self", "axis"]) + def cumsum(self, axis: Axis = 0, *args, **kwargs) -> NDFrameT: """ Cumulative sum for each group. @@ -3441,12 +3440,12 @@ def cumsum(self, axis: Axis = 0) -> NDFrameT: ------- Series or DataFrame """ - nv.validate_groupby_func("cumsum", (), {}, ["numeric_only", "skipna"]) + nv.validate_groupby_func("cumsum", args, kwargs, ["numeric_only", "skipna"]) if axis != 0: - f = lambda x: x.cumsum(axis=axis) + f = lambda x: x.cumsum(axis=axis, **kwargs) return self._python_apply_general(f, self._selected_obj, is_transform=True) - return self._cython_transform("cumsum") + return self._cython_transform("cumsum", **kwargs) @final @Substitution(name="groupby") From 2a680be9f9c1a8a6cf5ae1db01f7cdaad56b5075 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 31 Dec 2022 19:28:28 +0530 Subject: [PATCH 05/16] update --- pandas/core/groupby/generic.py | 8 ++++---- pandas/core/groupby/groupby.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index f83749344e8ea..b7c1b115f1cd8 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -895,7 +895,7 @@ def fillna( @doc(Series.take.__doc__) @deprecate_nonkeyword_arguments( - verison="3.0", allowed_args=["self", "axis", "indices"] + version="3.0", allowed_args=["self", "axis", "indices"] ) def take( self, @@ -908,7 +908,7 @@ def take( @doc(Series.skew.__doc__) @deprecate_nonkeyword_arguments( - verison="3.0", allowed_args=["self", "axis", "skipna", "numeric_only"] + version="3.0", allowed_args=["self", "axis", "skipna", "numeric_only"] ) def skew( self, @@ -2276,7 +2276,7 @@ def fillna( @doc(DataFrame.take.__doc__) @deprecate_nonkeyword_arguments( - verison="3.0", allowed_args=["self", "indices", "axis"] + 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) @@ -2284,7 +2284,7 @@ def take(self, indices: TakeIndexer, axis: Axis | None = 0, **kwargs) -> DataFra @doc(DataFrame.skew.__doc__) @deprecate_nonkeyword_arguments( - verison="3.0", allowed_args=["self", "axis", "skipna", "numeric_only"] + version="3.0", allowed_args=["self", "axis", "skipna", "numeric_only"] ) def skew( self, diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 3620f90a1a96e..ec62768085639 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -3412,7 +3412,7 @@ def rank( @final @Substitution(name="groupby") @Appender(_common_see_also) - @deprecate_nonkeyword_arguments(verison="3.0", allowed_args=["self", "axis"]) + @deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self", "axis"]) def cumprod(self, axis: Axis = 0, *args, **kwargs) -> NDFrameT: """ Cumulative product for each group. @@ -3431,7 +3431,7 @@ def cumprod(self, axis: Axis = 0, *args, **kwargs) -> NDFrameT: @final @Substitution(name="groupby") @Appender(_common_see_also) - @deprecate_nonkeyword_arguments(verison="3.0", allowed_args=["self", "axis"]) + @deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self", "axis"]) def cumsum(self, axis: Axis = 0, *args, **kwargs) -> NDFrameT: """ Cumulative sum for each group. From 656900680d844133eb94e9be28c30ef3c499078c Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 31 Dec 2022 19:51:37 +0530 Subject: [PATCH 06/16] Update groupby.py --- pandas/core/groupby/groupby.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index ec62768085639..75dbb5882492a 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -69,8 +69,8 @@ class providing the base-class of operations. Appender, Substitution, cache_readonly, - doc, deprecate_nonkeyword_arguments, + doc, ) from pandas.core.dtypes.cast import ensure_dtype_can_hold_na From 3a150f63d357c3a6fac8931920c152e5b462e943 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 31 Dec 2022 20:01:32 +0530 Subject: [PATCH 07/16] Update generic.py --- pandas/core/groupby/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index b7c1b115f1cd8..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, ) @@ -99,7 +100,6 @@ from pandas.core.util.numba_ import maybe_use_numba from pandas.plotting import boxplot_frame_groupby -from pandas.util._decorators import deprecate_nonkeyword_arguments if TYPE_CHECKING: from pandas.core.generic import NDFrame From 519d9dab855edf9eeb543ef02a5ade665fb6cdc7 Mon Sep 17 00:00:00 2001 From: ram vikram singh Date: Sat, 31 Dec 2022 20:16:34 +0530 Subject: [PATCH 08/16] Update v2.0.0.rst --- doc/source/whatsnew/v2.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 88311b8d1199c..8fd4b259f4669 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -735,7 +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`) +- Deprecate argument ``**kwargs`` from :meth:`cummax`, :meth:`cummin`, :meth:`cumsum`, :meth:`cumprod`, :meth:`take` and :meth:`skew` (:issue:`50483`) - .. --------------------------------------------------------------------------- From 20c860670dc154dbd3912a97cd10b56656a96fd4 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 3 Jan 2023 12:55:15 +0530 Subject: [PATCH 09/16] added tests --- pandas/core/groupby/groupby.py | 6 +++++ .../test_deprecate_nonkeyword_arguments.py | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 75dbb5882492a..7b810b4b65602 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -3450,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: @@ -3475,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/util/test_deprecate_nonkeyword_arguments.py b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py index 2ea3dae19a3e4..15a383409fae8 100644 --- a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py +++ b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py @@ -5,6 +5,16 @@ import inspect import warnings +from pandas.core.groupby.generic import ( + skew, + take, +) +from pandas.core.groupby.groupby import ( + cummax, + cummin, + cumprod, + cumsum, +) from pandas.util._decorators import deprecate_nonkeyword_arguments import pandas._testing as tm @@ -155,3 +165,15 @@ def test_class(): ) with tm.assert_produces_warning(FutureWarning, match=msg): Foo().baz("qux", "quox") + + +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): + assert cummax + assert cummin + assert cumprod + assert cumsum + assert skew + assert take From b026a747d5fec3562669602ce5c957670be3df2a Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 3 Jan 2023 13:00:32 +0530 Subject: [PATCH 10/16] Update v2.0.0.rst --- doc/source/whatsnew/v2.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 8fd4b259f4669..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`) .. --------------------------------------------------------------------------- @@ -735,7 +736,6 @@ 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`) - .. --------------------------------------------------------------------------- From dfed6256dc3f9764b033bb1fc163f879441ac612 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 3 Jan 2023 13:10:54 +0530 Subject: [PATCH 11/16] Update test_deprecate_nonkeyword_arguments.py --- .../util/test_deprecate_nonkeyword_arguments.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py index 15a383409fae8..a89d988ca2b8c 100644 --- a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py +++ b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py @@ -5,6 +5,10 @@ import inspect import warnings +from pandas.util._decorators import deprecate_nonkeyword_arguments + +import pandas._testing as tm + from pandas.core.groupby.generic import ( skew, take, @@ -15,9 +19,7 @@ cumprod, cumsum, ) -from pandas.util._decorators import deprecate_nonkeyword_arguments -import pandas._testing as tm @deprecate_nonkeyword_arguments( @@ -168,8 +170,10 @@ def test_class(): def test_deprecated_keywords(): - msg=("In the future version of pandas the arguments args" - "and kwargs will be deprecated for these functions") + 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): assert cummax assert cummin From 1676d192c31dbe6c9cffe44a7237dbf5dec48aca Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 3 Jan 2023 13:35:22 +0530 Subject: [PATCH 12/16] Update test_deprecate_nonkeyword_arguments.py --- pandas/tests/util/test_deprecate_nonkeyword_arguments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py index a89d988ca2b8c..17dd30a01959b 100644 --- a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py +++ b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py @@ -170,7 +170,7 @@ def test_class(): def test_deprecated_keywords(): - msg=( + msg = ( "In the future version of pandas the arguments args" "and kwargs will be deprecated for these functions" ) From b3ca2f2a3ec6cd999b8b7427c7e42a6c3f2bf096 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 3 Jan 2023 14:05:56 +0530 Subject: [PATCH 13/16] Update test_deprecate_nonkeyword_arguments.py --- pandas/tests/util/test_deprecate_nonkeyword_arguments.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py index 17dd30a01959b..96f6ba2be3768 100644 --- a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py +++ b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py @@ -21,7 +21,6 @@ ) - @deprecate_nonkeyword_arguments( version="1.1", allowed_args=["a", "b"], name="f_add_inputs" ) From 90fb8dcd134c3a836de4ec690572f7f44b6a2b03 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 3 Jan 2023 14:16:48 +0530 Subject: [PATCH 14/16] Update test_deprecate_nonkeyword_arguments.py --- pandas/tests/util/test_deprecate_nonkeyword_arguments.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py index 96f6ba2be3768..b44bd7250b41e 100644 --- a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py +++ b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py @@ -8,7 +8,6 @@ from pandas.util._decorators import deprecate_nonkeyword_arguments import pandas._testing as tm - from pandas.core.groupby.generic import ( skew, take, From fe8f551d8b7f270d49917683f19cc67a65e22e56 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Mon, 9 Jan 2023 12:14:44 +0530 Subject: [PATCH 15/16] corrected the tests --- pandas/tests/groupby/test_function.py | 16 ++++++++++++ .../test_deprecate_nonkeyword_arguments.py | 25 ------------------- 2 files changed, 16 insertions(+), 25 deletions(-) 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) diff --git a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py index b44bd7250b41e..8b0b74b34d850 100644 --- a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py +++ b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py @@ -8,17 +8,6 @@ from pandas.util._decorators import deprecate_nonkeyword_arguments import pandas._testing as tm -from pandas.core.groupby.generic import ( - skew, - take, -) -from pandas.core.groupby.groupby import ( - cummax, - cummin, - cumprod, - cumsum, -) - @deprecate_nonkeyword_arguments( version="1.1", allowed_args=["a", "b"], name="f_add_inputs" @@ -165,17 +154,3 @@ def test_class(): ) with tm.assert_produces_warning(FutureWarning, match=msg): Foo().baz("qux", "quox") - - -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): - assert cummax - assert cummin - assert cumprod - assert cumsum - assert skew - assert take From e45c8ff164c324e9ee3514896cbcf58d6df19f91 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Mon, 9 Jan 2023 12:23:16 +0530 Subject: [PATCH 16/16] Update test_deprecate_nonkeyword_arguments.py --- pandas/tests/util/test_deprecate_nonkeyword_arguments.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py index 8b0b74b34d850..2ea3dae19a3e4 100644 --- a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py +++ b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py @@ -9,6 +9,7 @@ import pandas._testing as tm + @deprecate_nonkeyword_arguments( version="1.1", allowed_args=["a", "b"], name="f_add_inputs" )