summaryrefslogtreecommitdiff
path: root/numpy/lib/shape_base.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-02-08 17:22:11 +0000
committerEric Wieser <wieser.eric@gmail.com>2017-02-11 21:09:20 +0000
commit78084ee261eae43e3b6cb12abee7d7880c62bc0c (patch)
tree494d7e487c58dbdb4056b47a29a02b1a764667a8 /numpy/lib/shape_base.py
parentff9c363bb729a37f09c63937e45d5870501bfbad (diff)
downloadnumpy-78084ee261eae43e3b6cb12abee7d7880c62bc0c.tar.gz
MAINT: Improve error-checking of axis argument
Copied from the implementation in core.shape_base.stack
Diffstat (limited to 'numpy/lib/shape_base.py')
-rw-r--r--numpy/lib/shape_base.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py
index 9c16982c4..da0b6a5b2 100644
--- a/numpy/lib/shape_base.py
+++ b/numpy/lib/shape_base.py
@@ -96,11 +96,10 @@ def apply_along_axis(func1d, axis, arr, *args, **kwargs):
# handle negative axes
arr = asanyarray(arr)
nd = arr.ndim
+ if not (-nd <= axis < nd):
+ raise IndexError('axis {0} out of bounds [-{1}, {1})'.format(axis, nd))
if axis < 0:
axis += nd
- if axis >= nd:
- raise ValueError("axis must be less than arr.ndim; axis=%d, rank=%d."
- % (axis, nd))
# arr, with the iteration axis at the end
in_dims = list(range(nd))