summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/lib/function_base.py3
-rw-r--r--numpy/lib/tests/test_function_base.py4
2 files changed, 6 insertions, 1 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 43bd3af8b..500394a38 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -3694,7 +3694,8 @@ def insert(arr, obj, values, axis=None):
# turn it into a range object
indices = arange(*obj.indices(N),**{'dtype':intp})
else:
- indices = np.asarray(obj)
+ # need to copy obj, because indices will be changed in-place
+ indices = np.array(obj)
if indices.dtype == bool:
# See also delete
warnings.warn("in the future insert will treat boolean arrays "
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index ae68be41f..5342aff4b 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -231,6 +231,10 @@ class TestInsert(TestCase):
a = np.array(1).view(SubClass)
assert_(isinstance(np.insert(a, 0, [0]), SubClass))
+ def test_index_array_copied(self):
+ x = np.array([1, 1, 1])
+ np.insert([0, 1, 2], x, [3, 4, 5])
+ assert_equal(x, np.array([1, 1, 1]))
class TestAmax(TestCase):
def test_basic(self):