diff options
author | Julian Taylor <juliantaylor108@gmail.com> | 2014-02-19 18:41:42 +0100 |
---|---|---|
committer | Julian Taylor <juliantaylor108@gmail.com> | 2014-02-19 18:41:42 +0100 |
commit | 3aaf365b34158ceca0f80cb42e64a7e362302214 (patch) | |
tree | 378e177e2b404c4925a65f2037d2d3d6d3d2d655 | |
parent | 8997167e0de90b7132787ff869ba7988783bb133 (diff) | |
parent | c513585f5a5eb16fc5d06f161de89a5989f3537d (diff) | |
download | numpy-3aaf365b34158ceca0f80cb42e64a7e362302214.tar.gz |
Merge pull request #4329 from seberg/index-casting-rule
BUG: Index arrays need to be cast with SAME_KIND or FORCE casting
-rw-r--r-- | numpy/core/src/multiarray/mapping.c | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_indexing.py | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c index 056ca6133..f3ed2bbd0 100644 --- a/numpy/core/src/multiarray/mapping.c +++ b/numpy/core/src/multiarray/mapping.c @@ -2379,7 +2379,7 @@ PyArray_MapIterCheckIndices(PyArrayMapIterObject *mit) NPY_ITER_BUFFERED | NPY_ITER_NBO | NPY_ITER_ALIGNED | NPY_ITER_EXTERNAL_LOOP | NPY_ITER_GROWINNER | NPY_ITER_READONLY, - NPY_KEEPORDER, NPY_SAFE_CASTING, intp_type); + NPY_KEEPORDER, NPY_SAME_KIND_CASTING, intp_type); if (op_iter == NULL) { Py_DECREF(intp_type); diff --git a/numpy/core/tests/test_indexing.py b/numpy/core/tests/test_indexing.py index 20032bc28..736210722 100644 --- a/numpy/core/tests/test_indexing.py +++ b/numpy/core/tests/test_indexing.py @@ -42,6 +42,25 @@ class TestIndexing(TestCase): a = np.array([np.array(1)], dtype=object) assert_(isinstance(a[0.], np.ndarray)) + def test_same_kind_index_casting(self): + # Indexes should be cast with same-kind and not safe, even if + # that is somewhat unsafe. So test various different code paths. + index = np.arange(5) + u_index = index.astype(np.uintp) + arr = np.arange(10) + + assert_array_equal(arr[index], arr[u_index]) + arr[u_index] = np.arange(5) + assert_array_equal(arr, np.arange(10)) + + arr = np.arange(10).reshape(5, 2) + assert_array_equal(arr[index], arr[u_index]) + + arr[u_index] = np.arange(5)[:,None] + assert_array_equal(arr, np.arange(5)[:,None].repeat(2, axis=1)) + + arr = np.arange(25).reshape(5, 5) + assert_array_equal(arr[u_index, u_index], arr[index, index]) def test_empty_fancy_index(self): # Empty list index creates an empty array |