diff options
-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], |