Skip to content

Commit b90f421

Browse files
committed
catch too-negative values
1 parent 7c4d281 commit b90f421

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pandas/compat/numpy/function.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ def validate_minmax_axis(axis):
376376
ValueError
377377
"""
378378
ndim = 1 # hard-coded for Index
379-
if axis is not None and axis >= ndim:
379+
if axis is None:
380+
return
381+
if axis >= ndim or (axis < 0 and ndim - axis < 0):
380382
raise ValueError("`axis` must be fewer than the number of "
381383
"dimensions ({ndim})".format(ndim=ndim))

pandas/tests/indexes/datetimelike.py

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ def test_argmax_axis_invalid(self):
1515
rng.argmax(axis=1)
1616
with pytest.raises(ValueError):
1717
rng.argmin(axis=2)
18+
with pytest.raises(ValueError):
19+
rng.min(axis=-2)
20+
with pytest.raises(ValueError):
21+
rng.max(axis=-3)
1822

1923
def test_can_hold_identifiers(self):
2024
idx = self.create_index()

0 commit comments

Comments
 (0)