diff options
| author | seberg <sebastian@sipsolutions.net> | 2013-04-27 03:05:16 -0700 |
|---|---|---|
| committer | seberg <sebastian@sipsolutions.net> | 2013-04-27 03:05:16 -0700 |
| commit | 0d9eac4bb25d43f3908efc54fd59348345e06c54 (patch) | |
| tree | 20be82eba1adf096e44fe5dd9b067d321073dd64 /numpy | |
| parent | f8a21eff6a93022f31e995b41d6fe28f16e39a12 (diff) | |
| parent | 0a9da01121b0f13d4e87fa44fbff7ba04472e314 (diff) | |
| download | numpy-0d9eac4bb25d43f3908efc54fd59348345e06c54.tar.gz | |
Merge pull request #3280 from seberg/issue-3279
BUG: np.insert must copy index array
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/lib/function_base.py | 3 | ||||
| -rw-r--r-- | numpy/lib/tests/test_function_base.py | 4 |
2 files changed, 6 insertions, 1 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 399f761ba..1ead53c87 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3695,7 +3695,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 ca329aae6..45e248913 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -232,6 +232,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): |
