From cf95e34475c9dcbfd377ee61bb9bbb0af9305d88 Mon Sep 17 00:00:00 2001 From: Arno Veenstra Date: Thu, 14 Feb 2019 12:02:21 +0100 Subject: [PATCH] Deprecate numeric_only --- pandas/core/arrays/categorical.py | 6 ++++-- pandas/core/series.py | 13 +++++++++++-- pandas/tests/reductions/test_reductions.py | 6 ++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index d9e77e9a362f83..8a4851e547b382 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -2179,7 +2179,8 @@ def _reduce(self, name, axis=0, **kwargs): raise TypeError(msg.format(op=name)) return func(**kwargs) - def min(self, skipna=True, **kwargs): + @deprecate_kwarg(old_arg_name='numeric_only', new_arg_name='skipna') + def min(self, skipna=True, numeric_only=None, **kwargs): """ The minimum value of the object. @@ -2205,7 +2206,8 @@ def min(self, skipna=True, **kwargs): else: return self.categories[pointer] - def max(self, skipna=True, **kwargs): + @deprecate_kwarg(old_arg_name='numeric_only', new_arg_name='skipna') + def max(self, skipna=True, numeric_only=None, **kwargs): """ The maximum value of the object. diff --git a/pandas/core/series.py b/pandas/core/series.py index b2011fdcdee981..cde26e56528531 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3674,8 +3674,17 @@ def _reduce(self, op, name, axis=0, skipna=True, numeric_only=None, if axis is not None: self._get_axis_number(axis) - # dispatch to ExtensionArray interface - if isinstance(delegate, ExtensionArray): + if isinstance(delegate, Categorical): + # TODO: remove numeric_only argument and treat Categorical the same + # as all ExtensionArrays + # See https://github.com/pandas-dev/pandas/issues/25303 + if numeric_only is not None: + return delegate._reduce(name, numeric_only=numeric_only, + **kwds) + else: + return delegate._reduce(name, skipna=skipna, **kwds) + elif isinstance(delegate, ExtensionArray): + # dispatch to ExtensionArray interface return delegate._reduce(name, skipna=skipna, **kwds) elif is_datetime64_dtype(delegate): # use DatetimeIndex implementation to handle skipna correctly diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 0df880a41fe59e..1066bc2a6129cb 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -967,6 +967,12 @@ def test_min_max(self): assert _min == "b" assert _max == "c" + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + _min = cat.min(numeric_only=False) + _max = cat.max(numeric_only=False) + assert np.isnan(_min) + assert _max == "c" + class TestSeriesMode(object): # Note: the name TestSeriesMode indicates these tests