8000 MAINT: Improve error-checking of axis argument · numpy/numpy@78084ee · GitHub
[go: up one dir, main page]

Skip to content

Commit 78084ee

Browse files
committed
MAINT: Improve error-checking of axis argument
Copied from the implementation in core.shape_base.stack
1 parent ff9c363 commit 78084ee

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

numpy/lib/shape_base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,10 @@ def apply_along_axis(func1d, axis, arr, *args, **kwargs):
9696
# handle negative axes
9797
arr = asanyarray(arr)
9898
nd = arr.ndim
99+
if not (-nd <= axis < nd):
100+
raise IndexError('axis {0} out of bounds [-{1}, {1})'.format(axis, nd))
99101
if axis < 0:
100102
axis += nd
101-
if axis >= nd:
102-
raise ValueError("axis must be less than arr.ndim; axis=%d, rank=%d."
103-
% (axis, nd))
104103

105104
# arr, with the iteration axis at the end
106105
in_dims = list(range(nd))

0 commit comments

Comments
 (0)
0