diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-02-08 22:05:11 +0000 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-02-20 22:03:05 +0000 |
commit | 370b6506f128460371484a50c813d66e64582f44 (patch) | |
tree | 31470f73a17e41608865d900228796800c4bb988 /numpy/lib/shape_base.py | |
parent | 763589d5adbda6230b30ba054cda7206dd14d379 (diff) | |
download | numpy-370b6506f128460371484a50c813d66e64582f44.tar.gz |
MAINT: Use normalize_axis_index in all python axis checking
As a result, some exceptions change from ValueError to IndexError
This also changes the exception types raised in places where
normalize_axis_index is not quite appropriate
Diffstat (limited to 'numpy/lib/shape_base.py')
-rw-r--r-- | numpy/lib/shape_base.py | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py index 58e13533b..62798286f 100644 --- a/numpy/lib/shape_base.py +++ b/numpy/lib/shape_base.py @@ -7,6 +7,7 @@ from numpy.core.numeric import ( asarray, zeros, outer, concatenate, isscalar, array, asanyarray ) from numpy.core.fromnumeric import product, reshape, transpose +from numpy.core.multiarray import normalize_axis_index from numpy.core import vstack, atleast_3d from numpy.lib.index_tricks import ndindex from numpy.matrixlib.defmatrix import matrix # this raises all the right alarm bells @@ -96,10 +97,7 @@ 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 + axis = normalize_axis_index(axis, nd) # arr, with the iteration axis at the end in_dims = list(range(nd)) @@ -289,8 +287,7 @@ def expand_dims(a, axis): """ a = asarray(a) shape = a.shape - if axis < 0: - axis = axis + len(shape) + 1 + axis = normalize_axis_index(axis, a.ndim + 1) return a.reshape(shape[:axis] + (1,) + shape[axis:]) row_stack = vstack |