diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 62e508c491740..5353969d9a556 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1956,6 +1956,7 @@ def min(self, *, skipna=True, **kwargs): ------- min : the minimum of this `Categorical` """ + nv.validate_minmax_axis(kwargs.get("axis", 0)) nv.validate_min((), kwargs) self.check_for_ordered("min") @@ -1992,6 +1993,7 @@ def max(self, *, skipna=True, **kwargs): ------- max : the maximum of this `Categorical` """ + nv.validate_minmax_axis(kwargs.get("axis", 0)) nv.validate_max((), kwargs) self.check_for_ordered("max") diff --git a/pandas/tests/arrays/categorical/test_analytics.py b/pandas/tests/arrays/categorical/test_analytics.py index 7bd7d29ec9703..abf4ddd681d69 100644 --- a/pandas/tests/arrays/categorical/test_analytics.py +++ b/pandas/tests/arrays/categorical/test_analytics.py @@ -113,6 +113,8 @@ def test_numpy_min_max_unsupported_kwargs_raises(self, method, kwarg): f"the '{kwarg}' parameter is not supported in the pandas implementation " f"of {method}" ) + if kwarg == "axis": + msg = r"`axis` must be fewer than the number of dimensions \(1\)" kwargs = {kwarg: 42} method = getattr(np, method) with pytest.raises(ValueError, match=msg): diff --git a/pandas/tests/indexes/datetimelike.py b/pandas/tests/indexes/datetimelike.py index 7ce8640d09777..14f9c2f9de284 100644 --- a/pandas/tests/indexes/datetimelike.py +++ b/pandas/tests/indexes/datetimelike.py @@ -10,19 +10,6 @@ class DatetimeLike(Base): - def test_argmax_axis_invalid(self): - # GH#23081 - msg = r"`axis` must be fewer than the number of dimensions \(1\)" - rng = self.create_index() - with pytest.raises(ValueError, match=msg): - rng.argmax(axis=1) - with pytest.raises(ValueError, match=msg): - rng.argmin(axis=2) - with pytest.raises(ValueError, match=msg): - rng.min(axis=-2) - with pytest.raises(ValueError, match=msg): - rng.max(axis=-3) - def test_can_hold_identifiers(self): idx = self.create_index() key = idx[0] diff --git a/pandas/tests/indexes/test_any_index.py b/pandas/tests/indexes/test_any_index.py index 5e7065f785309..afeeb63217489 100644 --- a/pandas/tests/indexes/test_any_index.py +++ b/pandas/tests/indexes/test_any_index.py @@ -89,3 +89,17 @@ def test_str(self, index): index.name = "foo" assert "'foo'" in str(index) assert type(index).__name__ in str(index) + + +class TestReductions: + def test_argmax_axis_invalid(self, index): + # GH#23081 + msg = r"`axis` must be fewer than the number of dimensions \(1\)" + with pytest.raises(ValueError, match=msg): + index.argmax(axis=1) + with pytest.raises(ValueError, match=msg): + index.argmin(axis=2) + with pytest.raises(ValueError, match=msg): + index.min(axis=-2) + with pytest.raises(ValueError, match=msg): + index.max(axis=-3)