diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 4466dc0afad1..73f39fce192e 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -3264,7 +3264,7 @@ def __setitem__(self, indx, value): 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 9b65643edde0..5a1ed2be820a 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -4256,6 +4256,13 @@ def test_setitem(self): 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']: