8000 BUG: retain writeable flag when indexing subclasses by juliantaylor · Pull Request #4843 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: retain writeable flag when indexing subclasses #4843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions numpy/core/src/multiarray/mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,9 @@ array_boolean_subscript(PyArrayObject *self,
Py_DECREF(ret);
return NULL;
}
if (_IsWriteable(ret)) {
PyArray_ENABLEFLAGS(ret, NPY_ARRAY_WRITEABLE);
}
}

return ret;
Expand Down Expand Up @@ -1583,6 +1586,9 @@ array_subscript(PyArrayObject *self, PyObject *op)
result = NULL;
goto finish;
}
if (_IsWriteable(result)) {
PyArray_ENABLEFLAGS(result, NPY_ARRAY_WRITEABLE);
}
}

finish:
Expand Down
11 changes: 11 additions & 0 deletions numpy/core/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,17 @@ def __array_finalize__(self, old):
assert_((a == 1).all())


def test_subclass_writeable(self):
d = np.rec.array([('NGC1001', 11), ('NGC1002', 1.), ('NGC1003', 1.)],
dtype=[('target', 'S20'), ('V_mag', '>f4')])
ind = np.array([False, True, True], dtype=bool)
assert_(d[ind].flags.writeable)
ind = np.array([0, 1])
assert_(d[ind].flags.writeable)
assert_(d[...].flags.writeable)
assert_(d[0].flags.writeable)


def test_memory_order(self):
# This is not necessary to preserve. Memory layouts for
# more complex indices are not as simple.
Expand Down
0