summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-02-08 22:05:11 +0000
committerEric Wieser <wieser.eric@gmail.com>2017-02-20 22:03:05 +0000
commit370b6506f128460371484a50c813d66e64582f44 (patch)
tree31470f73a17e41608865d900228796800c4bb988 /numpy/lib/function_base.py
parent763589d5adbda6230b30ba054cda7206dd14d379 (diff)
downloadnumpy-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/function_base.py')
-rw-r--r--numpy/lib/function_base.py13
1 files changed, 4 insertions, 9 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index ae1420b72..4d1ffbccc 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -25,7 +25,7 @@ from numpy.core.numerictypes import typecodes, number
from numpy.lib.twodim_base import diag
from .utils import deprecate
from numpy.core.multiarray import (
- _insert, add_docstring, digitize, bincount,
+ _insert, add_docstring, digitize, bincount, normalize_axis_index,
interp as compiled_interp, interp_complex as compiled_interp_complex
)
from numpy.core.umath import _add_newdoc_ufunc as add_newdoc_ufunc
@@ -4828,14 +4828,7 @@ def insert(arr, obj, values, axis=None):
arr = arr.ravel()
ndim = arr.ndim
axis = ndim - 1
- else:
- if ndim > 0 and (axis < -ndim or axis >= ndim):
- raise IndexError(
- "axis %i is out of bounds for an array of "
- "dimension %i" % (axis, ndim))
- if (axis < 0):
- axis += ndim
- if (ndim == 0):
+ elif ndim == 0:
# 2013-09-24, 1.9
warnings.warn(
"in the future the special handling of scalars will be removed "
@@ -4846,6 +4839,8 @@ def insert(arr, obj, values, axis=None):
return wrap(arr)
else:
return arr
+ else:
+ axis = normalize_axis_index(axis, ndim)
slobj = [slice(None)]*ndim
N = arr.shape[axis]
newshape = list(arr.shape)