diff options
author | njsmith <njs@pobox.com> | 2013-09-24 00:47:47 -0700 |
---|---|---|
committer | njsmith <njs@pobox.com> | 2013-09-24 00:47:47 -0700 |
commit | 99ee78a112065a22f91ea4f39ec58b3513de68e3 (patch) | |
tree | 1c82909e4a5f5c27522a1d1104b2be423677b526 /numpy | |
parent | 0a389625ab97b788cbef4afb9c91467b8c745692 (diff) | |
parent | 094ebf78b231bf314bb88881546365d48a6b6c22 (diff) | |
download | numpy-99ee78a112065a22f91ea4f39ec58b3513de68e3.tar.gz |
Merge pull request #3757 from dimasad/issue-3017-fix
BUG: fix #3017 Inconsistency in indexing 0-d arrays with Ellipsis.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/mapping.c | 6 | ||||
-rw-r--r-- | numpy/core/tests/test_indexing.py | 5 |
2 files changed, 9 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c index 3cdde9afe..2bf5ef9ec 100644 --- a/numpy/core/src/multiarray/mapping.c +++ b/numpy/core/src/multiarray/mapping.c @@ -1391,7 +1391,9 @@ array_ass_sub(PyArrayObject *self, PyObject *ind, PyObject *op) } /* Ellipsis index */ - if (ind == Py_Ellipsis) { + if (ind == Py_Ellipsis || + (PyTuple_Check(ind) && 1 == PyTuple_GET_SIZE(ind) && + Py_Ellipsis == PyTuple_GET_ITEM(ind, 0))) { /* * Doing "a[...] += 1" triggers assigning an array to itself, * so this check is needed. @@ -1408,7 +1410,7 @@ array_ass_sub(PyArrayObject *self, PyObject *ind, PyObject *op) /* * Several different exceptions to the 0-d no-indexing rule * - * 1) ellipses (handled above generally) + * 1) ellipses or tuple with ellipses (handled above generally) * 2) empty tuple * 3) Using newaxis (None) * 4) Boolean mask indexing diff --git a/numpy/core/tests/test_indexing.py b/numpy/core/tests/test_indexing.py index 89e28af78..ad792eb08 100644 --- a/numpy/core/tests/test_indexing.py +++ b/numpy/core/tests/test_indexing.py @@ -54,6 +54,11 @@ class TestIndexing(TestCase): # in an array, not a scalar assert_equal(a[0, ..., 1], np.array(2)) + # Assignment with `(Ellipsis,)` on 0-d arrays + b = np.array(1) + b[(Ellipsis,)] = 2 + assert_equal(b, 2) + def test_single_int_index(self): # Single integer index selects one row a = np.array([[1, 2, 3], |