From 899befaea6881e4aa0fae8fe9ac128792756ad50 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 27 Sep 2022 16:50:56 -0700 Subject: [PATCH 1/4] DEPR: Enforce deprecation of Categorical.min/max(numeric_only) --- pandas/core/arrays/categorical.py | 7 +------ pandas/tests/arrays/categorical/test_analytics.py | 9 --------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index ee995a0f9d0b7..866622fc7d204 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -49,10 +49,7 @@ type_t, ) from pandas.compat.numpy import function as nv -from pandas.util._decorators import ( - deprecate_kwarg, - deprecate_nonkeyword_arguments, -) +from pandas.util._decorators import deprecate_nonkeyword_arguments from pandas.util._exceptions import find_stack_level from pandas.util._validators import validate_bool_kwarg @@ -2299,7 +2296,6 @@ def _reverse_indexer(self) -> dict[Hashable, npt.NDArray[np.intp]]: # ------------------------------------------------------------------ # Reductions - @deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna") def min(self, *, skipna: bool = True, **kwargs): """ The minimum value of the object. @@ -2336,7 +2332,6 @@ def min(self, *, skipna: bool = True, **kwargs): pointer = self._codes.min() return self._wrap_reduction_result(None, pointer) - @deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna") def max(self, *, skipna: bool = True, **kwargs): """ The maximum value of the object. diff --git a/pandas/tests/arrays/categorical/test_analytics.py b/pandas/tests/arrays/categorical/test_analytics.py index 1a8dbe25c0b75..58a8ad410cf6a 100644 --- a/pandas/tests/arrays/categorical/test_analytics.py +++ b/pandas/tests/arrays/categorical/test_analytics.py @@ -104,15 +104,6 @@ def test_min_max_only_nan(self, function, skipna): result = getattr(cat, function)(skipna=skipna) assert result is np.nan - @pytest.mark.parametrize("method", ["min", "max"]) - def test_deprecate_numeric_only_min_max(self, method): - # GH 25303 - cat = Categorical( - [np.nan, 1, 2, np.nan], categories=[5, 4, 3, 2, 1], ordered=True - ) - with tm.assert_produces_warning(expected_warning=FutureWarning): - getattr(cat, method)(numeric_only=True) - @pytest.mark.parametrize("method", ["min", "max"]) def test_numpy_min_max_raises(self, method): cat = Categorical(["a", "b", "c", "b"], ordered=False) From 2841bacee51a5537beb9be381fb99c55fff34f80 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 13 Oct 2022 11:31:58 -0700 Subject: [PATCH 2/4] Turn test into raises --- pandas/tests/arrays/categorical/test_analytics.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pandas/tests/arrays/categorical/test_analytics.py b/pandas/tests/arrays/categorical/test_analytics.py index 58a8ad410cf6a..39590bcc6636e 100644 --- a/pandas/tests/arrays/categorical/test_analytics.py +++ b/pandas/tests/arrays/categorical/test_analytics.py @@ -104,6 +104,15 @@ def test_min_max_only_nan(self, function, skipna): result = getattr(cat, function)(skipna=skipna) assert result is np.nan + @pytest.mark.parametrize("method", ["min", "max"]) + def test_numeric_only_min_max_raises(self, method): + # GH 25303 + cat = Categorical( + [np.nan, 1, 2, np.nan], categories=[5, 4, 3, 2, 1], ordered=True + ) + with pytest.raises(TypeError, match=".* got an unexpected keyword"): + getattr(cat, method)(numeric_only=True) + @pytest.mark.parametrize("method", ["min", "max"]) def test_numpy_min_max_raises(self, method): cat = Categorical(["a", "b", "c", "b"], ordered=False) From 4accc04810913f1cb022c24edc22c4dba8db9aa5 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 19 Oct 2022 09:30:42 -0700 Subject: [PATCH 3/4] Add whatsnew --- doc/source/whatsnew/v2.0.0.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 596c16a5b3621..75542b327ea47 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -145,7 +145,8 @@ Deprecations Removal of prior version deprecations/changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`) -- Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`) +- Removed :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`) +- Removed the ``numeric_only`` keyword from :meth:`Categorical.min` and :meth:`Categorical.max` in favor of ``skipna`` (:issue:`48821`) .. --------------------------------------------------------------------------- .. _whatsnew_200.performance: From 0f3a24fd229757a1a8aeb30259efa7e9b55d4ed1 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 19 Oct 2022 16:21:50 -0700 Subject: [PATCH 4/4] Update doc/source/whatsnew/v2.0.0.rst --- doc/source/whatsnew/v2.0.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 9dc17016de6f7..281dd1feca522 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -145,7 +145,6 @@ Deprecations Removal of prior version deprecations/changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`) -- Removed :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`) - Removed the ``numeric_only`` keyword from :meth:`Categorical.min` and :meth:`Categorical.max` in favor of ``skipna`` (:issue:`48821`) - Removed :func:`is_extension_type` in favor of :func:`is_extension_array_dtype` (:issue:`29457`) - Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`)