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",