summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2021-08-13 08:32:01 +0300
committerGitHub <noreply@github.com>2021-08-13 08:32:01 +0300
commit42c2cbe714e9e3709018cfa46fd9f71516d1e895 (patch)
tree0f95181f7ffb9a85e0ee118ba29df347f974bd72 /numpy
parent9a1229f86ca4d4041c9aa48027a21c7ad97da748 (diff)
parentb92df509ca6767f65891b1b0eac6e64ee7621ee4 (diff)
downloadnumpy-42c2cbe714e9e3709018cfa46fd9f71516d1e895.tar.gz
Merge pull request #19244 from iameskild/fix_18951
BUG: Fix an issue wherein assigment to `np.ma.masked_array` ignores mask in index
Diffstat (limited to 'numpy')
-rw-r--r--numpy/ma/core.py7
-rw-r--r--numpy/ma/tests/test_old_ma.py7
2 files changed, 12 insertions, 2 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index d2150919f..ca9f4f474 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -3374,8 +3374,11 @@ class MaskedArray(ndarray):
_mask[indx] = mval
elif not self._hardmask:
# Set the data, then the mask
- _data[indx] = dval
- _mask[indx] = mval
+ if isinstance(indx, masked_array):
+ _data[indx.data] = dval
+ else:
+ _data[indx] = dval
+ _mask[indx] = mval
elif hasattr(indx, 'dtype') and (indx.dtype == MaskType):
indx = indx * umath.logical_not(_mask)
_data[indx] = dval
diff --git a/numpy/ma/tests/test_old_ma.py b/numpy/ma/tests/test_old_ma.py
index ab003b94e..2e0097dc8 100644
--- a/numpy/ma/tests/test_old_ma.py
+++ b/numpy/ma/tests/test_old_ma.py
@@ -697,6 +697,13 @@ class TestMa:
assert_equal(b[0].shape, ())
assert_equal(b[1].shape, ())
+ def test_assignment_by_condition(self):
+ # Test for gh-18951
+ a = array([1, 2, 3, 4], mask=[1, 0, 1, 0])
+ c = a >= 3
+ a[c] = 5
+ assert_(a[2] is masked)
+
class TestUfuncs:
def setup(self):