Skip to content

Commit b97ec96

Browse files
committed
move axis validation to nv
1 parent c903917 commit b97ec96

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

pandas/compat/numpy/function.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,22 @@ def validate_resampler_func(method, args, kwargs):
360360
"{func}() instead".format(func=method)))
361361
else:
362362
raise TypeError("too many arguments passed in")
363+
364+
365+
def validate_minmax_axis(axis):
366+
"""
367+
Ensure that the axis argument passed to min, max, argmin, or argmax is
368+
zero or None, as otherwise it will be incorrectly ignored.
369+
370+
Parameters
371+
----------
372+
axis : int or None
373+
374+
Raises
375+
------
376+
ValueError
377+
"""
378+
ndim = 1 # hard-coded for Index
379+
if axis is not None and axis >= ndim:
380+
raise ValueError("`axis` must be fewer than the number of "
381+
"dimensions ({ndim})".format(ndim=ndim))

pandas/core/indexes/datetimelike.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ def min(self, axis=None, *args, **kwargs):
430430
--------
431431
numpy.ndarray.min
432432
"""
433-
_validate_minmax_axis(axis)
433+
nv.validate_minmax_axis(axis)
434434
nv.validate_min(args, kwargs)
435435

436436
try:
@@ -459,7 +459,7 @@ def argmin(self, axis=None, *args, **kwargs):
459459
--------
460460
numpy.ndarray.argmin
461461
"""
462-
_validate_minmax_axis(axis)
462+
nv.validate_minmax_axis(axis)
463463
nv.validate_argmin(args, kwargs)
464464

465465
i8 = self.asi8
@@ -480,7 +480,7 @@ def max(self, axis=None, *args, **kwargs):
480480
--------
481481
numpy.ndarray.max
482482
"""
483-
_validate_minmax_axis(axis)
483+
nv.validate_minmax_axis(axis)
484484
nv.validate_max(args, kwargs)
485485

486486
try:
@@ -509,7 +509,7 @@ def argmax(self, axis=None, *args, **kwargs):
509509
--------
510510
numpy.ndarray.argmax
511511
"""
512-
_validate_minmax_axis(axis)
512+
nv.validate_minmax_axis(axis)
513513
nv.validate_argmax(args, kwargs)
514514

515515
i8 = self.asi8
@@ -710,25 +710,6 @@ def _time_shift(self, periods, freq=None):
710710
return result
711711

712712

713-
def _validate_minmax_axis(axis):
714-
"""
715-
Ensure that the axis argument passed to min, max, argmin, or argmax is
716-
zero or None, as otherwise it will be incorrectly ignored.
717-
718-
Parameters
719-
----------
720-
axis : int or None
721-
722-
Raises
723-
------
724-
ValueError
725-
"""
726-
ndim = 1 # hard-coded for Index
727-
if axis is not None and axis >= ndim:
728-
raise ValueError("`axis` must be fewer than the number of "
729-
"dimensions ({ndim})".format(ndim=ndim))
730-
731-
732713
def _ensure_datetimelike_to_i8(other, to_utc=False):
733714
"""
734715
helper for coercing an input scalar or array to i8

0 commit comments

Comments
 (0)