diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index ab58f86e0a6bcd..0105aa1c0ddcea 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -2172,7 +2172,7 @@ def _reverse_indexer(self): return result # reduction ops # - def _reduce(self, name, axis=0, skipna=True, **kwargs): + def _reduce(self, name, axis=0, **kwargs): func = getattr(self, name, None) if func is None: msg = 'Categorical cannot perform the operation {op}' diff --git a/pandas/core/series.py b/pandas/core/series.py index b2011fdcdee981..6ee00ecbfcf514 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3674,8 +3674,12 @@ 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 deprecate numeric_only argument for Categorical and use + # skipna as well + return delegate._reduce(name, numeric_only=numeric_only, **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 173f719edd4655..9fca678def406f 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -960,6 +960,18 @@ def test_min_max(self): assert np.isnan(_min) assert _max == 1 + cat = Series(Categorical( + ["a", "b", "c", "a"], categories=["b", "c", "d"], ordered=True)) + _min = cat.min(numeric_only=True) + _max = cat.max(numeric_only=True) + assert _min == "b" + assert _max == "c" + + _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