From 948eca4b74d9d11b3638a7b6ed711b74987d5bf2 Mon Sep 17 00:00:00 2001 From: Ambuj Pawar Date: Fri, 23 Sep 2022 15:40:22 +0200 Subject: [PATCH 1/9] Deprecate positional arguments in favor of keyword arguments --- pandas/core/generic.py | 1 + pandas/core/groupby/generic.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f023e5b6adf04..9e45a67886de2 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6710,6 +6710,7 @@ def fillna( def fillna( self: NDFrameT, value: Hashable | Mapping | Series | DataFrame = None, + *, method: FillnaOptions | None = None, axis: Axis | None = None, inplace: bool_t = False, diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 6a2070eb4f46f..178744be13797 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -753,6 +753,7 @@ def build_codes(lev_codes: np.ndarray) -> np.ndarray: def fillna( self, value: object | ArrayLike | None = None, + *, method: FillnaOptions | None = None, axis: Axis | None = None, inplace: bool = False, @@ -2075,6 +2076,7 @@ def value_counts( def fillna( self, value: Hashable | Mapping | Series | DataFrame = None, + *, method: FillnaOptions | None = None, axis: Axis | None = None, inplace: bool = False, From ca1d1d01c8d3fb465fbe8e1ef0ca99b2f26d65c1 Mon Sep 17 00:00:00 2001 From: Ambuj Pawar Date: Fri, 23 Sep 2022 15:53:18 +0200 Subject: [PATCH 2/9] add entry to whatsnew --- doc/source/whatsnew/v1.6.0.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.6.0.rst b/doc/source/whatsnew/v1.6.0.rst index ae062ca30a9fa..c47e030e3860b 100644 --- a/doc/source/whatsnew/v1.6.0.rst +++ b/doc/source/whatsnew/v1.6.0.rst @@ -235,7 +235,8 @@ Plotting Groupby/resample/rolling ^^^^^^^^^^^^^^^^^^^^^^^^ - Bug in :meth:`DataFrameGroupBy.sample` raises ``ValueError`` when the object is empty (:issue:`48459`) -- +- Deprecated behaviour of :meth:`DataFrameGroupBy.fillna`, :meth:`SeriesGroupBy.fillna` allowing only keyword arguments except value(:issue:`48395`) + Reshaping ^^^^^^^^^ From a4b02569489711d2709ef3476c69ea04892c70db Mon Sep 17 00:00:00 2001 From: Ambuj Pawar Date: Fri, 30 Sep 2022 09:41:51 +0200 Subject: [PATCH 3/9] Fix: Review comments for deprecation PR --- doc/source/whatsnew/v1.6.0.rst | 3 +-- pandas/core/generic.py | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.6.0.rst b/doc/source/whatsnew/v1.6.0.rst index c47e030e3860b..9964675796f14 100644 --- a/doc/source/whatsnew/v1.6.0.rst +++ b/doc/source/whatsnew/v1.6.0.rst @@ -123,7 +123,7 @@ Other API changes Deprecations ~~~~~~~~~~~~ -- +- Deprecated behaviour of :meth:`DataFrameGroupBy.fillna`, :meth:`SeriesGroupBy.fillna` allowing only keyword arguments except value(:issue:`48395`) - .. --------------------------------------------------------------------------- @@ -235,7 +235,6 @@ Plotting Groupby/resample/rolling ^^^^^^^^^^^^^^^^^^^^^^^^ - Bug in :meth:`DataFrameGroupBy.sample` raises ``ValueError`` when the object is empty (:issue:`48459`) -- Deprecated behaviour of :meth:`DataFrameGroupBy.fillna`, :meth:`SeriesGroupBy.fillna` allowing only keyword arguments except value(:issue:`48395`) Reshaping diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 9e45a67886de2..f023e5b6adf04 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6710,7 +6710,6 @@ def fillna( def fillna( self: NDFrameT, value: Hashable | Mapping | Series | DataFrame = None, - *, method: FillnaOptions | None = None, axis: Axis | None = None, inplace: bool_t = False, From e2602e002e56a4c1ea3d0e86641b111f53b9f043 Mon Sep 17 00:00:00 2001 From: Ambuj Pawar Date: Sat, 8 Oct 2022 11:50:37 +0200 Subject: [PATCH 4/9] Change whatsnew --- doc/source/whatsnew/v1.6.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.6.0.rst b/doc/source/whatsnew/v1.6.0.rst index 1e8dd7bddcd96..734cd8ac64d4c 100644 --- a/doc/source/whatsnew/v1.6.0.rst +++ b/doc/source/whatsnew/v1.6.0.rst @@ -125,7 +125,6 @@ Other API changes Deprecations ~~~~~~~~~~~~ -- Deprecated behaviour of :meth:`DataFrameGroupBy.fillna`, :meth:`SeriesGroupBy.fillna` allowing only keyword arguments except value(:issue:`48395`) - .. --------------------------------------------------------------------------- @@ -207,6 +206,7 @@ Indexing - Bug in :meth:`DataFrame.reindex` filling with wrong values when indexing columns and index for ``uint`` dtypes (:issue:`48184`) - Bug in :meth:`DataFrame.reindex` casting dtype to ``object`` when :class:`DataFrame` has single extension array column when re-indexing ``columns`` and ``index`` (:issue:`48190`) - Bug in :func:`~DataFrame.describe` when formatting percentiles in the resulting index showed more decimals than needed (:issue:`46362`) +- :meth:`DataFrameGroupBy.fillna` and :meth:`SeriesGroupBy.fillna` now allow only keyword arguments to be passed except value(:issue:`48395`) Missing ^^^^^^^ From 4562ba62231e9033e8ad5f71adbc3a4e6a832689 Mon Sep 17 00:00:00 2001 From: Ambuj Pawar Date: Wed, 12 Oct 2022 09:24:21 +0200 Subject: [PATCH 5/9] Change value to ``value`` --- doc/source/whatsnew/v1.6.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.6.0.rst b/doc/source/whatsnew/v1.6.0.rst index 6d3c910f045f1..0d0c340957600 100644 --- a/doc/source/whatsnew/v1.6.0.rst +++ b/doc/source/whatsnew/v1.6.0.rst @@ -214,7 +214,7 @@ Indexing - Bug in :meth:`DataFrame.reindex` filling with wrong values when indexing columns and index for ``uint`` dtypes (:issue:`48184`) - Bug in :meth:`DataFrame.reindex` casting dtype to ``object`` when :class:`DataFrame` has single extension array column when re-indexing ``columns`` and ``index`` (:issue:`48190`) - Bug in :func:`~DataFrame.describe` when formatting percentiles in the resulting index showed more decimals than needed (:issue:`46362`) -- :meth:`DataFrameGroupBy.fillna` and :meth:`SeriesGroupBy.fillna` now allow only keyword arguments to be passed except value(:issue:`48395`) +- :meth:`DataFrameGroupBy.fillna` and :meth:`SeriesGroupBy.fillna` now allow only keyword arguments to be passed except ``value`` (:issue:`48395`) Missing ^^^^^^^ From ac961d0d0f1d4c2c4f8d49dc397afa22b8514638 Mon Sep 17 00:00:00 2001 From: Ambuj Pawar Date: Sun, 16 Oct 2022 20:51:54 +0200 Subject: [PATCH 6/9] Move change from indexing to deprecations --- doc/source/whatsnew/v1.6.0.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.6.0.rst b/doc/source/whatsnew/v1.6.0.rst index 0d0c340957600..79dafcf4d87fa 100644 --- a/doc/source/whatsnew/v1.6.0.rst +++ b/doc/source/whatsnew/v1.6.0.rst @@ -127,7 +127,8 @@ Other API changes Deprecations ~~~~~~~~~~~~ -- +- Deprecate behavior of :meth:`DataFrameGroupBy.fillna` and :meth:`SeriesGroupBy.fillna` allowing only keyword arguments to be passed except ``value`` (:issue:`48395`) + .. --------------------------------------------------------------------------- .. _whatsnew_160.performance: @@ -214,7 +215,6 @@ Indexing - Bug in :meth:`DataFrame.reindex` filling with wrong values when indexing columns and index for ``uint`` dtypes (:issue:`48184`) - Bug in :meth:`DataFrame.reindex` casting dtype to ``object`` when :class:`DataFrame` has single extension array column when re-indexing ``columns`` and ``index`` (:issue:`48190`) - Bug in :func:`~DataFrame.describe` when formatting percentiles in the resulting index showed more decimals than needed (:issue:`46362`) -- :meth:`DataFrameGroupBy.fillna` and :meth:`SeriesGroupBy.fillna` now allow only keyword arguments to be passed except ``value`` (:issue:`48395`) Missing ^^^^^^^ From 87c525bc3a99e50ce0e02fb7b9625d88e4784c91 Mon Sep 17 00:00:00 2001 From: Ambuj Pawar Date: Sun, 16 Oct 2022 21:22:17 +0200 Subject: [PATCH 7/9] ADD: Deprecation warning --- doc/source/whatsnew/v2.0.0.rst | 3 +-- pandas/core/groupby/generic.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 2b9611843c2f8..602b94bcd6029 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -131,7 +131,6 @@ Other API changes Deprecations ~~~~~~~~~~~~ -- Deprecate behavior of :meth:`DataFrameGroupBy.fillna` and :meth:`SeriesGroupBy.fillna` allowing only keyword arguments to be passed except ``value`` (:issue:`48395`) .. --------------------------------------------------------------------------- @@ -221,7 +220,6 @@ Indexing - Bug in :meth:`DataFrame.reindex` casting dtype to ``object`` when :class:`DataFrame` has single extension array column when re-indexing ``columns`` and ``index`` (:issue:`48190`) - Bug in :func:`~DataFrame.describe` when formatting percentiles in the resulting index showed more decimals than needed (:issue:`46362`) - Bug in :meth:`DataFrame.compare` does not recognize differences when comparing ``NA`` with value in nullable dtypes (:issue:`48939`) -- Missing ^^^^^^^ @@ -295,6 +293,7 @@ Metadata Other ^^^^^ +- Add future warnings in :meth:`DataFrameGroupBy.fillna` and :meth:`SeriesGroupBy.fillna` allowing only keyword arguments to be passed except ``value`` (:issue:`48395`) .. ***DO NOT USE THIS SECTION*** diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index cb54373afbe4a..341eea5ce24c0 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -748,7 +748,6 @@ def build_codes(lev_codes: np.ndarray) -> np.ndarray: def fillna( self, value: object | ArrayLike | None = None, - *, method: FillnaOptions | None = None, axis: Axis | None = None, inplace: bool = False, @@ -841,6 +840,12 @@ def fillna( 5 NaN dtype: float64 """ + warnings.warn( + 'In a future version of pandas, all the parameters except "value" ' + "of SeriesGroupBy.fillna have to be keyword-only.", + FutureWarning, + stacklevel=find_stack_level(), + ) result = self._op_via_apply( "fillna", value=value, @@ -2151,7 +2156,6 @@ def value_counts( def fillna( self, value: Hashable | Mapping | Series | DataFrame = None, - *, method: FillnaOptions | None = None, axis: Axis | None = None, inplace: bool = False, @@ -2269,6 +2273,12 @@ def fillna( 3 3.0 NaN 2.0 4 3.0 NaN NaN """ + warnings.warn( + 'In a future version of pandas, all the parameters except "value" ' + "of DataFrameGroupBy.fillna have to be keyword-only.", + FutureWarning, + stacklevel=find_stack_level(), + ) result = self._op_via_apply( "fillna", value=value, From c39993cb92c82ad96c5cb57048d1bdbf4af4d5f0 Mon Sep 17 00:00:00 2001 From: Ambuj Pawar Date: Wed, 26 Oct 2022 18:54:29 +0200 Subject: [PATCH 8/9] use deprecation decorators instead of warning --- pandas/core/groupby/generic.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 835c404627e1b..65f7c2d1b361a 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -101,6 +101,7 @@ from pandas.core.series import Series from pandas.core.shared_docs import _shared_docs from pandas.core.util.numba_ import maybe_use_numba +from pandas.utils._decorators import deprecate_nonkeyword_arguments from pandas.plotting import boxplot_frame_groupby @@ -745,6 +746,7 @@ def build_codes(lev_codes: np.ndarray) -> np.ndarray: out = ensure_int64(out) return self.obj._constructor(out, index=mi, name=self.obj.name) + @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "value"]) def fillna( self, value: object | ArrayLike | None = None, @@ -840,12 +842,6 @@ def fillna( 5 NaN dtype: float64 """ - warnings.warn( - 'In a future version of pandas, all the parameters except "value" ' - "of SeriesGroupBy.fillna have to be keyword-only.", - FutureWarning, - stacklevel=find_stack_level(), - ) result = self._op_via_apply( "fillna", value=value, @@ -2153,6 +2149,7 @@ def value_counts( result = result_frame return result.__finalize__(self.obj, method="value_counts") + @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "value"]) def fillna( self, value: Hashable | Mapping | Series | DataFrame = None, @@ -2273,12 +2270,6 @@ def fillna( 3 3.0 NaN 2.0 4 3.0 NaN NaN """ - warnings.warn( - 'In a future version of pandas, all the parameters except "value" ' - "of DataFrameGroupBy.fillna have to be keyword-only.", - FutureWarning, - stacklevel=find_stack_level(), - ) result = self._op_via_apply( "fillna", value=value, From ec1b703c91d36b6c41fc3825f447acd472574ed6 Mon Sep 17 00:00:00 2001 From: Ambuj Pawar Date: Wed, 26 Oct 2022 22:12:53 +0200 Subject: [PATCH 9/9] fix: typo in import --- 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 2809da45cb829..edbcd373a3e13 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -50,6 +50,7 @@ from pandas.util._decorators import ( Appender, Substitution, + deprecate_nonkeyword_arguments, doc, ) from pandas.util._exceptions import find_stack_level @@ -101,7 +102,6 @@ from pandas.core.series import Series from pandas.core.shared_docs import _shared_docs from pandas.core.util.numba_ import maybe_use_numba -from pandas.utils._decorators import deprecate_nonkeyword_arguments from pandas.plotting import boxplot_frame_groupby