Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REF: share argmax axis validation test across all indexes #38049

Merged
merged 2 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/arrays/categorical/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 0 additions & 13 deletions pandas/tests/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/indexes/test_any_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)