Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7434481

Browse files
committed
DEP: Allow high dim boolean assignment, but deprecate it
1 parent 480432b commit 7434481

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

numpy/core/src/multiarray/mapping.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,23 @@ array_assign_subscript(PyArrayObject *self, PyObject *ind, PyObject *op)
17961796
Py_INCREF(op);
17971797
tmp_arr = (PyArrayObject *)op;
17981798
}
1799+
1800+
/*
1801+
* Deprecated case. The old boolean indexing seemed to have some
1802+
* check to allow wrong dimensional boolean arrays in all cases.
1803+
* Note that it did *not* allow a wrong number of elements here.
1804+
*/
1805+
if (PyArray_NDIM(tmp_arr) > 1) {
1806+
PyArrayObject *unraveled_tmp = tmp_arr;
1807+
if (DEPRECATE("boolean assignment blah blah.") < 0) {
1808+
goto fail;
1809+
}
1810+
tmp_arr = (PyArrayObject *)PyArray_Ravel(unraveled_tmp, NPY_CORDER);
1811+
Py_DECREF(unraveled_tmp);
1812+
if (tmp_arr == NULL) {
1813+
goto fail;
1814+
}
1815+
}
17991816
if (array_assign_boolean_subscript(self,
18001817
(PyArrayObject *)indices[0].object,
18011818
tmp_arr, NPY_CORDER) < 0) {

0 commit comments

Comments
 (0)