From cb6fe848bf1a6a046fd473b72b1350ea40c8644e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Hartmann?= Date: Wed, 3 Jul 2013 00:16:58 +0200 Subject: BUG: Fix bug in np.insert when axis=-1 --- numpy/lib/function_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 5e433d3ab..9f1757d7c 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3742,7 +3742,7 @@ def insert(arr, obj, values, axis=None): # broadcasting is very different here, since a[:,0,:] = ... behaves # very different from a[:,[0],:] = ...! This changes values so that # it works likes the second case. (here a[:,0:1,:]) - values = np.rollaxis(values, 0, axis+1) + values = np.rollaxis(values, 0, axis % ndim + 1) numnew = values.shape[axis] newshape[axis] += numnew new = empty(newshape, arr.dtype, arr.flags.fnc) -- cgit v1.2.1 From ea768739dab69c0b67488179ffa67d57d63d59f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Hartmann?= Date: Tue, 9 Jul 2013 15:49:32 +0200 Subject: BUG: Make np.insert check for out of bounds axis arguments. Also add test for IndexError exception when axis is out of bounds. --- numpy/lib/function_base.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 9f1757d7c..17f99a065 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3696,6 +3696,11 @@ 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): warnings.warn("in the future the special handling of scalars " "will be removed from insert and raise an error", @@ -3742,7 +3747,7 @@ def insert(arr, obj, values, axis=None): # broadcasting is very different here, since a[:,0,:] = ... behaves # very different from a[:,[0],:] = ...! This changes values so that # it works likes the second case. (here a[:,0:1,:]) - values = np.rollaxis(values, 0, axis % ndim + 1) + values = np.rollaxis(values, 0, axis + 1) numnew = values.shape[axis] newshape[axis] += numnew new = empty(newshape, arr.dtype, arr.flags.fnc) -- cgit v1.2.1