Skip to content

Commit 07ca75a

Browse files
authored
REF: share argmax axis validation test across all indexes (#38049)
1 parent 3391a34 commit 07ca75a

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

pandas/core/arrays/categorical.py

+2
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,7 @@ def min(self, *, skipna=True, **kwargs):
19561956
-------
19571957
min : the minimum of this `Categorical`
19581958
"""
1959+
nv.validate_minmax_axis(kwargs.get("axis", 0))
19591960
nv.validate_min((), kwargs)
19601961
self.check_for_ordered("min")
19611962

@@ -1992,6 +1993,7 @@ def max(self, *, skipna=True, **kwargs):
19921993
-------
19931994
max : the maximum of this `Categorical`
19941995
"""
1996+
nv.validate_minmax_axis(kwargs.get("axis", 0))
19951997
nv.validate_max((), kwargs)
19961998
self.check_for_ordered("max")
19971999

pandas/tests/arrays/categorical/test_analytics.py

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ def test_numpy_min_max_unsupported_kwargs_raises(self, method, kwarg):
113113
f"the '{kwarg}' parameter is not supported in the pandas implementation "
114114
f"of {method}"
115115
)
116+
if kwarg == "axis":
117+
msg = r"`axis` must be fewer than the number of dimensions \(1\)"
116118
kwargs = {kwarg: 42}
117119
method = getattr(np, method)
118120
with pytest.raises(ValueError, match=msg):

pandas/tests/indexes/datetimelike.py

-13
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@
1010

1111

1212
class DatetimeLike(Base):
13-
def test_argmax_axis_invalid(self):
14-
# GH#23081
15-
msg = r"`axis` must be fewer than the number of dimensions \(1\)"
16-
rng = self.create_index()
17-
with pytest.raises(ValueError, match=msg):
18-
rng.argmax(axis=1)
19-
with pytest.raises(ValueError, match=msg):
20-
rng.argmin(axis=2)
21-
with pytest.raises(ValueError, match=msg):
22-
rng.min(axis=-2)
23-
with pytest.raises(ValueError, match=msg):
24-
rng.max(axis=-3)
25-
2613
def test_can_hold_identifiers(self):
2714
idx = self.create_index()
2815
key = idx[0]

pandas/tests/indexes/test_any_index.py

+14
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,17 @@ def test_str(self, index):
8989
index.name = "foo"
9090
assert "'foo'" in str(index)
9191
assert type(index).__name__ in str(index)
92+
93+
94+
class TestReductions:
95+
def test_argmax_axis_invalid(self, index):
96+
# GH#23081
97+
msg = r"`axis` must be fewer than the number of dimensions \(1\)"
98+
with pytest.raises(ValueError, match=msg):
99+
index.argmax(axis=1)
100+
with pytest.raises(ValueError, match=msg):
101+
index.argmin(axis=2)
102+
with pytest.raises(ValueError, match=msg):
103+
index.min(axis=-2)
104+
with pytest.raises(ValueError, match=msg):
105+
index.max(axis=-3)

0 commit comments

Comments
 (0)