8000 BUG: Remove incorrect flags propagation in boolean indexing · numpy/numpy@cee5f86 · GitHub
[go: up one dir, main page]

Skip to content

Commit cee5f86

Browse files
committed
BUG: Remove incorrect flags propagation in boolean indexing
Flags don't need to be propagated from the original array. Progating from the result array makes sense and is safe, but really... the only flag we normally need is writeable. (However, this is a typical pattern right now.) Expands the test to cover these cases. Closes gh-27777
1 parent 773a30b commit cee5f86

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

numpy/_core/src/multiarray/mapping.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ array_boolean_subscript(PyArrayObject *self,
10581058
ret = (PyArrayObject *)PyArray_NewFromDescrAndBase(
10591059
Py_TYPE(self), ret_dtype,
10601060
1, &size, PyArray_STRIDES(ret), PyArray_BYTES(ret),
1061-
PyArray_FLAGS(self), (PyObject *)self, (PyObject *)tmp);
1061+
PyArray_FLAGS(ret), (PyObject *)self, (PyObject *)tmp);
10621062

10631063
Py_DECREF(tmp);
10641064
if (ret == NULL) {

numpy/_core/tests/test_indexing.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,15 +409,19 @@ def test_array_like_values(self):
409409
a[...] = memoryview(s)
410410
assert_array_equal(a, s)
411411

412-
def test_subclass_writeable(self):
412+
@pytest.mark.parametrize("writeable", [True, False])
413+
def test_subclass_writeable(self, writeable):
413414
d = np.rec.array([('NGC1001', 11), ('NGC1002', 1.), ('NGC1003', 1.)],
414415
dtype=[('target', 'S20'), ('V_mag', '>f4')])
416+
d.flags.writeable = writeable
417+
# Advanced indexing results are always writeable:
415418
ind = np.array([False, True, True], dtype=bool)
416-
assert_(d[ind].flags.writeable)
419+
assert d[ind].flags.writeable
417420
ind = np.array([0, 1])
418-
assert_(d[ind].flags.writeable)
419-
assert_(d[...].flags.writeable)
420-
assert_(d[0].flags.writeable)
421+
assert d[ind].flags.writeable
422+
# Views should be writeable if the original array is:
423+
assert d[...].flags.writeable == writeable
424+
assert d[0].flags.writeable == writeable
421425

422426
def test_memory_order(self):
423427
# This is not necessary to preserve. Memory layouts for

0 commit comments

Comments
 (0)
0