summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authora-elhag <48454648+a-elhag@users.noreply.github.com>2020-12-07 12:15:17 -0500
committerGitHub <noreply@github.com>2020-12-07 11:15:17 -0600
commit905075211bb0bae80cb7f837419180f25a253dd5 (patch)
tree4d010eca735bc83c11312efe21e47888042b4666 /numpy/core
parenta3c09377e80a37deedc486ec30a7e852b7a8e564 (diff)
downloadnumpy-905075211bb0bae80cb7f837419180f25a253dd5.tar.gz
BUG: numpy.putmask not respecting writeable flag (#17884)
* BUG: numpy.putmask not respecting writeable flag * Made the code PEP8 compatible. Fixes gh-17871.
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/src/multiarray/item_selection.c4
-rw-r--r--numpy/core/tests/test_multiarray.py7
2 files changed, 11 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c
index 8052e24e4..b279ffc2f 100644
--- a/numpy/core/src/multiarray/item_selection.c
+++ b/numpy/core/src/multiarray/item_selection.c
@@ -576,6 +576,10 @@ PyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0)
return NULL;
}
+ if (PyArray_FailUnlessWriteable(self, "putmask: output array") < 0) {
+ return NULL;
+ }
+
mask = (PyArrayObject *)PyArray_FROM_OTF(mask0, NPY_BOOL,
NPY_ARRAY_CARRAY | NPY_ARRAY_FORCECAST);
if (mask == NULL) {
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 2df92ee65..048b1688f 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -4643,6 +4643,13 @@ class TestPutmask:
np.putmask(x[1:4], x[:3], [True, False, True])
assert_equal(x, np.array([True, True, True, True]))
+ def test_writeable(self):
+ a = np.arange(5)
+ a.flags.writeable = False
+
+ with pytest.raises(ValueError):
+ np.putmask(a, a >= 2, 3)
+
class TestTake:
def tst_basic(self, x):