From 9fab4625de8d4ca9235e5a63ce860d6ff23b3f76 Mon Sep 17 00:00:00 2001 From: makbigc Date: Thu, 15 Aug 2019 18:30:07 +0800 Subject: [PATCH 1/9] Deprecate numeric_only parameter in Categorical.min and max --- doc/source/whatsnew/v0.25.1.rst | 5 +++ pandas/core/arrays/categorical.py | 34 ++++++++++--------- pandas/core/series.py | 4 +-- .../arrays/categorical/test_analytics.py | 29 ++++++++++------ pandas/tests/reductions/test_reductions.py | 20 ++++------- 5 files changed, 50 insertions(+), 42 deletions(-) diff --git a/doc/source/whatsnew/v0.25.1.rst b/doc/source/whatsnew/v0.25.1.rst index 63dd56f4a3793..711c5205b2860 100644 --- a/doc/source/whatsnew/v0.25.1.rst +++ b/doc/source/whatsnew/v0.25.1.rst @@ -16,6 +16,11 @@ For example, on MacOS installing Python with `pyenv` may lead to an incomplete P .. _whatsnew_0251.bug_fixes: +Other deprecations +^^^^^^^^^^^^^^^^^^ + +- The parameter ``numeric_only`` of :meth:`Categorical.min` and :meth:`Categorical.max` is deprecated and replaced with ``skipna`` (:issue:`25303`) + Bug fixes ~~~~~~~~~ diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 43e52cb011324..5f56065240b36 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -2196,7 +2196,8 @@ def _reduce(self, name, axis=0, **kwargs): raise TypeError(msg.format(op=name)) return func(**kwargs) - def min(self, numeric_only=None, **kwargs): + @deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna") + def min(self, skipna=True, **kwargs): """ The minimum value of the object. @@ -2212,17 +2213,18 @@ def min(self, numeric_only=None, **kwargs): min : the minimum of this `Categorical` """ self.check_for_ordered("min") - if numeric_only: - good = self._codes != -1 - pointer = self._codes[good].min(**kwargs) + good = self._codes != -1 + if good.any(): + if skipna: + pointer = self._codes[good].min(**kwargs) + else: + return np.nan else: pointer = self._codes.min(**kwargs) - if pointer == -1: - return np.nan - else: - return self.categories[pointer] + return self.categories[pointer] - def max(self, numeric_only=None, **kwargs): + @deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna") + def max(self, skipna=True, **kwargs): """ The maximum value of the object. @@ -2238,15 +2240,15 @@ def max(self, numeric_only=None, **kwargs): max : the maximum of this `Categorical` """ self.check_for_ordered("max") - if numeric_only: - good = self._codes != -1 - pointer = self._codes[good].max(**kwargs) + good = self._codes != -1 + if good.any(): + if skipna: + pointer = self._codes[good].max(**kwargs) + else: + return np.nan else: pointer = self._codes.max(**kwargs) - if pointer == -1: - return np.nan - else: - return self.categories[pointer] + return self.categories[pointer] def mode(self, dropna=True): """ diff --git a/pandas/core/series.py b/pandas/core/series.py index 97e8a2dbac7f5..65e8ccc95d555 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3980,9 +3980,7 @@ def _reduce( self._get_axis_number(axis) if isinstance(delegate, Categorical): - # TODO deprecate numeric_only argument for Categorical and use - # skipna as well, see GH25303 - return delegate._reduce(name, numeric_only=numeric_only, **kwds) + return delegate._reduce(name, skipna=skipna, **kwds) elif isinstance(delegate, ExtensionArray): # dispatch to ExtensionArray interface return delegate._reduce(name, skipna=skipna, **kwds) diff --git a/pandas/tests/arrays/categorical/test_analytics.py b/pandas/tests/arrays/categorical/test_analytics.py index 279f1492d7dad..b08691203920b 100644 --- a/pandas/tests/arrays/categorical/test_analytics.py +++ b/pandas/tests/arrays/categorical/test_analytics.py @@ -38,29 +38,38 @@ def test_min_max(self): cat = Categorical( [np.nan, "b", "c", np.nan], categories=["d", "c", "b", "a"], ordered=True ) - _min = cat.min() - _max = cat.max() + _min = cat.min(skipna=False) + _max = cat.max(skipna=False) assert np.isnan(_min) - assert _max == "b" + assert np.isnan(_max) - _min = cat.min(numeric_only=True) + _min = cat.min() assert _min == "c" - _max = cat.max(numeric_only=True) + _max = cat.max() assert _max == "b" cat = Categorical( [np.nan, 1, 2, np.nan], categories=[5, 4, 3, 2, 1], ordered=True ) - _min = cat.min() - _max = cat.max() + _min = cat.min(skipna=False) + _max = cat.max(skipna=False) assert np.isnan(_min) - assert _max == 1 + assert np.isnan(_max) - _min = cat.min(numeric_only=True) + _min = cat.min() assert _min == 2 - _max = cat.max(numeric_only=True) + _max = cat.max() assert _max == 1 + @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=False) + @pytest.mark.parametrize( "values,categories,exp_mode", [ diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 05ebff4387908..155aab5bf4839 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -1028,7 +1028,7 @@ def test_min_max(self): ) _min = cat.min() _max = cat.max() - assert np.isnan(_min) + assert _min == "c" assert _max == "b" cat = Series( @@ -1038,30 +1038,24 @@ def test_min_max(self): ) _min = cat.min() _max = cat.max() - assert np.isnan(_min) + assert _min == 2 assert _max == 1 - def test_min_max_numeric_only(self): - # TODO deprecate numeric_only argument for Categorical and use - # skipna as well, see GH25303 + def test_min_max_skipna(self): + # GH 25303 cat = Series( Categorical(["a", "b", np.nan, "a"], categories=["b", "a"], ordered=True) ) _min = cat.min() _max = cat.max() - assert np.isnan(_min) - assert _max == "a" - - _min = cat.min(numeric_only=True) - _max = cat.max(numeric_only=True) assert _min == "b" assert _max == "a" - _min = cat.min(numeric_only=False) - _max = cat.max(numeric_only=False) + _min = cat.min(skipna=False) + _max = cat.max(skipna=False) assert np.isnan(_min) - assert _max == "a" + assert np.isnan(_max) class TestSeriesMode: From 4bfe68633dfbc98fcb99ea40f957ab065e35bd4e Mon Sep 17 00:00:00 2001 From: makbigc Date: Fri, 16 Aug 2019 22:41:52 +0800 Subject: [PATCH 2/9] Amend after 1st review --- doc/source/whatsnew/v0.25.1.rst | 5 --- doc/source/whatsnew/v1.0.0.rst | 1 + .../arrays/categorical/test_analytics.py | 37 ++++++++++--------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/doc/source/whatsnew/v0.25.1.rst b/doc/source/whatsnew/v0.25.1.rst index 711c5205b2860..63dd56f4a3793 100644 --- a/doc/source/whatsnew/v0.25.1.rst +++ b/doc/source/whatsnew/v0.25.1.rst @@ -16,11 +16,6 @@ For example, on MacOS installing Python with `pyenv` may lead to an incomplete P .. _whatsnew_0251.bug_fixes: -Other deprecations -^^^^^^^^^^^^^^^^^^ - -- The parameter ``numeric_only`` of :meth:`Categorical.min` and :meth:`Categorical.max` is deprecated and replaced with ``skipna`` (:issue:`25303`) - Bug fixes ~~~~~~~~~ diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 4816e6a519884..a3840413786e1 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -169,6 +169,7 @@ Deprecations - ``Index.set_value`` has been deprecated. For a given index ``idx``, array ``arr``, value in ``idx`` of ``idx_val`` and a new value of ``val``, ``idx.set_value(arr, idx_val, val)`` is equivalent to ``arr[idx.get_loc(idx_val)] = val``, which should be used instead (:issue:`28621`). +- The parameter ``numeric_only`` of :meth:`Categorical.min` and :meth:`Categorical.max` is deprecated and replaced with ``skipna`` (:issue:`25303`) - .. _whatsnew_1000.prior_deprecations: diff --git a/pandas/tests/arrays/categorical/test_analytics.py b/pandas/tests/arrays/categorical/test_analytics.py index b08691203920b..72a7c5540b047 100644 --- a/pandas/tests/arrays/categorical/test_analytics.py +++ b/pandas/tests/arrays/categorical/test_analytics.py @@ -35,31 +35,34 @@ def test_min_max(self): assert _min == "d" assert _max == "a" + @pytest.mark.parametrize("skipna", [True, False]) + def test_min_max_with_nan(self, skipna): + # GH 25303 cat = Categorical( [np.nan, "b", "c", np.nan], categories=["d", "c", "b", "a"], ordered=True ) - _min = cat.min(skipna=False) - _max = cat.max(skipna=False) - assert np.isnan(_min) - assert np.isnan(_max) + _min = cat.min(skipna=skipna) + _max = cat.max(skipna=skipna) - _min = cat.min() - assert _min == "c" - _max = cat.max() - assert _max == "b" + if skipna is False: + assert np.isnan(_min) + assert np.isnan(_max) + else: + assert _min == "c" + assert _max == "b" cat = Categorical( [np.nan, 1, 2, np.nan], categories=[5, 4, 3, 2, 1], ordered=True ) - _min = cat.min(skipna=False) - _max = cat.max(skipna=False) - assert np.isnan(_min) - assert np.isnan(_max) - - _min = cat.min() - assert _min == 2 - _max = cat.max() - assert _max == 1 + _min = cat.min(skipna=skipna) + _max = cat.max(skipna=skipna) + + if skipna is False: + assert np.isnan(_min) + assert np.isnan(_max) + else: + assert _min == 2 + assert _max == 1 @pytest.mark.parametrize("method", ["min", "max"]) def test_deprecate_numeric_only_min_max(self, method): From e4d5c3856c6e3a8a25884a34754c1731f6c1e779 Mon Sep 17 00:00:00 2001 From: makbigc Date: Fri, 16 Aug 2019 23:26:25 +0800 Subject: [PATCH 3/9] Parametrize test_min_max_skipna in reductions/test_reductions.py --- pandas/tests/reductions/test_reductions.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 155aab5bf4839..5b657e306c42b 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -1041,21 +1041,21 @@ def test_min_max(self): assert _min == 2 assert _max == 1 - def test_min_max_skipna(self): + @pytest.mark.parametrize("skipna", [True, False]) + def test_min_max_skipna(self, skipna): # GH 25303 cat = Series( Categorical(["a", "b", np.nan, "a"], categories=["b", "a"], ordered=True) ) + _min = cat.min(skipna=skipna) + _max = cat.max(skipna=skipna) - _min = cat.min() - _max = cat.max() - assert _min == "b" - assert _max == "a" - - _min = cat.min(skipna=False) - _max = cat.max(skipna=False) - assert np.isnan(_min) - assert np.isnan(_max) + if skipna is True: + assert _min == "b" + assert _max == "a" + else: + assert np.isnan(_min) + assert np.isnan(_max) class TestSeriesMode: From 300a86290f10d47e51fbf07a4b18c7e6f8c3f51b Mon Sep 17 00:00:00 2001 From: makbigc Date: Fri, 1 Nov 2019 21:21:26 +0800 Subject: [PATCH 4/9] Set skipna=None by default and add future warning --- pandas/core/arrays/categorical.py | 14 ++++++++++---- pandas/tests/arrays/categorical/test_analytics.py | 5 +++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 53c3f2e1c429a..e66b004e71ae5 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -2195,7 +2195,7 @@ def _reduce(self, name, axis=0, **kwargs): return func(**kwargs) @deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna") - def min(self, skipna=True, **kwargs): + def min(self, skipna=None, **kwargs): """ The minimum value of the object. @@ -2212,17 +2212,20 @@ def min(self, skipna=True, **kwargs): """ self.check_for_ordered("min") good = self._codes != -1 - if good.any(): + if not good.all(): if skipna: pointer = self._codes[good].min(**kwargs) else: + msg = ("The default value of skipna will be changed to " + "True in the future version.") + warn(msg, FutureWarning, stacklevel=2) return np.nan else: pointer = self._codes.min(**kwargs) return self.categories[pointer] @deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna") - def max(self, skipna=True, **kwargs): + def max(self, skipna=None, **kwargs): """ The maximum value of the object. @@ -2239,10 +2242,13 @@ def max(self, skipna=True, **kwargs): """ self.check_for_ordered("max") good = self._codes != -1 - if good.any(): + if not good.all(): if skipna: pointer = self._codes[good].max(**kwargs) else: + msg = ("The default value of skipna will be changed to " + "True in the future version.") + warn(msg, FutureWarning, stacklevel=2) return np.nan else: pointer = self._codes.max(**kwargs) diff --git a/pandas/tests/arrays/categorical/test_analytics.py b/pandas/tests/arrays/categorical/test_analytics.py index 72a7c5540b047..7e209626fe848 100644 --- a/pandas/tests/arrays/categorical/test_analytics.py +++ b/pandas/tests/arrays/categorical/test_analytics.py @@ -70,8 +70,9 @@ def test_deprecate_numeric_only_min_max(self, method): 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=False) + with tm.assert_produces_warning(expected_warning=FutureWarning, + check_stacklevel=False): + getattr(cat, method)(numeric_only=True) @pytest.mark.parametrize( "values,categories,exp_mode", From 095e6da6613fce89b39d3b5d095b87f465bbac02 Mon Sep 17 00:00:00 2001 From: makbigc Date: Fri, 1 Nov 2019 22:47:09 +0800 Subject: [PATCH 5/9] Fix black issue and the test error --- pandas/core/arrays/categorical.py | 18 ++++++++++++------ .../tests/arrays/categorical/test_analytics.py | 5 +++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index e66b004e71ae5..a9bd89635fe8e 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -2216,9 +2216,12 @@ def min(self, skipna=None, **kwargs): if skipna: pointer = self._codes[good].min(**kwargs) else: - msg = ("The default value of skipna will be changed to " - "True in the future version.") - warn(msg, FutureWarning, stacklevel=2) + if skipna is None: + msg = ( + "The default value of skipna will be changed to " + "True in the future version." + ) + warn(msg, FutureWarning, stacklevel=2) return np.nan else: pointer = self._codes.min(**kwargs) @@ -2246,9 +2249,12 @@ def max(self, skipna=None, **kwargs): if skipna: pointer = self._codes[good].max(**kwargs) else: - msg = ("The default value of skipna will be changed to " - "True in the future version.") - warn(msg, FutureWarning, stacklevel=2) + if skipna is None: + msg = ( + "The default value of skipna will be changed to " + "True in the future version." + ) + warn(msg, FutureWarning, stacklevel=2) return np.nan else: pointer = self._codes.max(**kwargs) diff --git a/pandas/tests/arrays/categorical/test_analytics.py b/pandas/tests/arrays/categorical/test_analytics.py index 7e209626fe848..39008488aece7 100644 --- a/pandas/tests/arrays/categorical/test_analytics.py +++ b/pandas/tests/arrays/categorical/test_analytics.py @@ -70,8 +70,9 @@ def test_deprecate_numeric_only_min_max(self, method): cat = Categorical( [np.nan, 1, 2, np.nan], categories=[5, 4, 3, 2, 1], ordered=True ) - with tm.assert_produces_warning(expected_warning=FutureWarning, - check_stacklevel=False): + with tm.assert_produces_warning( + expected_warning=FutureWarning, check_stacklevel=False + ): getattr(cat, method)(numeric_only=True) @pytest.mark.parametrize( From 7d731639249e4a3f1ca06c8840d3c998bcd5be9c Mon Sep 17 00:00:00 2001 From: makbigc Date: Fri, 22 Nov 2019 00:02:17 +0800 Subject: [PATCH 6/9] Set skipna=True and add section in API breaking --- doc/source/whatsnew/v1.0.0.rst | 21 +++++++++++++++++++++ pandas/core/arrays/categorical.py | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 8562a9168cd8c..46c063c236015 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -235,6 +235,27 @@ The following methods now also correctly output values for unobserved categories df.groupby(["cat_1", "cat_2"], observed=False)["value"].count() +By default :meth:`Categorical.min` and :meth:`Categorical.max` return the min and the max respectively +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +When :class:`Categorical` contains ``np.nan``, :meth:`Categorical.min` and :meth:`Categorical.max` +no longer return ``np.nan`` by default. + +*pandas 0.25.x* + +.. code-block:: ipython + + In [1]: pd.Categorical([1, 2, np.nan], ordered=True).min() + Out[1]: nan + + +*pandas 1.0.0* + +.. ipython:: python + + pd.Categorical([1, 2, np.nan], ordered=True).min() + + .. _whatsnew_1000.api.other: Other API changes diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 0aada33221809..26e24ea423f7e 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -2194,7 +2194,7 @@ def _reduce(self, name, axis=0, **kwargs): return func(**kwargs) @deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna") - def min(self, skipna=None, **kwargs): + def min(self, skipna=True, **kwargs): """ The minimum value of the object. @@ -2227,7 +2227,7 @@ def min(self, skipna=None, **kwargs): return self.categories[pointer] @deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna") - def max(self, skipna=None, **kwargs): + def max(self, skipna=True, **kwargs): """ The maximum value of the object. From 6a184c8fdf4bf7e20b287404d69662111014277a Mon Sep 17 00:00:00 2001 From: makbigc Date: Sat, 23 Nov 2019 23:56:54 +0800 Subject: [PATCH 7/9] Modify after review --- doc/source/whatsnew/v1.0.0.rst | 8 ++++---- pandas/core/arrays/categorical.py | 12 ------------ pandas/tests/arrays/categorical/test_analytics.py | 4 +--- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index decdc6b8c7250..f7426f2642421 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -235,11 +235,11 @@ The following methods now also correctly output values for unobserved categories df.groupby(["cat_1", "cat_2"], observed=False)["value"].count() -By default :meth:`Categorical.min` and :meth:`Categorical.max` return the min and the max respectively -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +By default :meth:`Categorical.min` return the min and the max respectively +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -When :class:`Categorical` contains ``np.nan``, :meth:`Categorical.min` and :meth:`Categorical.max` -no longer return ``np.nan`` by default. +When :class:`Categorical` contains ``np.nan``, +:meth:`Categorical.min` no longer return ``np.nan`` by default (skipna=True). *pandas 0.25.x* diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index cf14d13f99bb3..a88d15be6e156 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -2197,12 +2197,6 @@ def min(self, skipna=True, **kwargs): if skipna: pointer = self._codes[good].min(**kwargs) else: - if skipna is None: - msg = ( - "The default value of skipna will be changed to " - "True in the future version." - ) - warn(msg, FutureWarning, stacklevel=2) return np.nan else: pointer = self._codes.min(**kwargs) @@ -2230,12 +2224,6 @@ def max(self, skipna=True, **kwargs): if skipna: pointer = self._codes[good].max(**kwargs) else: - if skipna is None: - msg = ( - "The default value of skipna will be changed to " - "True in the future version." - ) - warn(msg, FutureWarning, stacklevel=2) return np.nan else: pointer = self._codes.max(**kwargs) diff --git a/pandas/tests/arrays/categorical/test_analytics.py b/pandas/tests/arrays/categorical/test_analytics.py index 39008488aece7..637a47eba0597 100644 --- a/pandas/tests/arrays/categorical/test_analytics.py +++ b/pandas/tests/arrays/categorical/test_analytics.py @@ -70,9 +70,7 @@ def test_deprecate_numeric_only_min_max(self, method): cat = Categorical( [np.nan, 1, 2, np.nan], categories=[5, 4, 3, 2, 1], ordered=True ) - with tm.assert_produces_warning( - expected_warning=FutureWarning, check_stacklevel=False - ): + with tm.assert_produces_warning(expected_warning=FutureWarning): getattr(cat, method)(numeric_only=True) @pytest.mark.parametrize( From 23ffd16123084cbf7478ce248b54586792e3f9c7 Mon Sep 17 00:00:00 2001 From: makbigc Date: Mon, 2 Dec 2019 17:34:45 +0800 Subject: [PATCH 8/9] Remove kwarg in categorical.min and max --- pandas/core/arrays/categorical.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index a89afe44467cc..6a7a225845440 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -2158,7 +2158,7 @@ def _reduce(self, name, axis=0, **kwargs): return func(**kwargs) @deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna") - def min(self, skipna=True, **kwargs): + def min(self, skipna=True): """ The minimum value of the object. @@ -2177,15 +2177,15 @@ def min(self, skipna=True, **kwargs): good = self._codes != -1 if not good.all(): if skipna: - pointer = self._codes[good].min(**kwargs) + pointer = self._codes[good].min() else: return np.nan else: - pointer = self._codes.min(**kwargs) + pointer = self._codes.min() return self.categories[pointer] @deprecate_kwarg(old_arg_name="numeric_only", new_arg_name="skipna") - def max(self, skipna=True, **kwargs): + def max(self, skipna=True): """ The maximum value of the object. @@ -2204,11 +2204,11 @@ def max(self, skipna=True, **kwargs): good = self._codes != -1 if not good.all(): if skipna: - pointer = self._codes[good].max(**kwargs) + pointer = self._codes[good].max() else: return np.nan else: - pointer = self._codes.max(**kwargs) + pointer = self._codes.max() return self.categories[pointer] def mode(self, dropna=True): From 260201cf5bc2419a229222f2258a4bb6d31b988c Mon Sep 17 00:00:00 2001 From: makbigc Date: Mon, 2 Dec 2019 17:37:48 +0800 Subject: [PATCH 9/9] Change wording in v1.0.0.rst --- doc/source/whatsnew/v1.0.0.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 086ae051e9cd3..ee5098749105f 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -260,8 +260,8 @@ The following methods now also correctly output values for unobserved categories df.groupby(["cat_1", "cat_2"], observed=False)["value"].count() -By default :meth:`Categorical.min` return the min and the max respectively -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +By default :meth:`Categorical.min` now returns the minimum instead of np.nan +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ When :class:`Categorical` contains ``np.nan``, :meth:`Categorical.min` no longer return ``np.nan`` by default (skipna=True) (:issue:`25303`)