summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-02-10 15:03:24 +0000
committerEric Wieser <wieser.eric@gmail.com>2017-02-20 20:09:51 +0000
commit10bf55e6548e970481baf7b333aeab20743e5b3b (patch)
tree0b7302888301cb4c895b1976f704e88e053ec5e0
parent1718ee8f8080c474c8e2167726c8aa542761135b (diff)
downloadnumpy-10bf55e6548e970481baf7b333aeab20743e5b3b.tar.gz
BUG: Fix #8510, making MaskedArray.__setitem__ work
-rw-r--r--numpy/ma/core.py2
-rw-r--r--numpy/ma/tests/test_core.py7
2 files changed, 8 insertions, 1 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 4466dc0af..73f39fce1 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -3264,7 +3264,7 @@ class MaskedArray(ndarray):
return
# Get the _data part of the new value
- dval = value
+ dval = getattr(value, '_data', value)
# Get the _mask part of the new value
mval = getattr(value, '_mask', nomask)
if nbfields and mval is nomask:
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 9b65643ed..5a1ed2be8 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -4256,6 +4256,13 @@ class TestMaskedFields(TestCase):
a[0]['a'] = 2
assert_equal(a.mask, control)
+ def test_setitem_scalar(self):
+ # 8510
+ mask_0d = np.ma.masked_array(1, mask=True)
+ arr = np.ma.arange(3)
+ arr[0] = mask_0d
+ assert_array_equal(arr.mask, [True, False, False])
+
def test_element_len(self):
# check that len() works for mvoid (Github issue #576)
for rec in self.data['base']: