From 10bf55e6548e970481baf7b333aeab20743e5b3b Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Fri, 10 Feb 2017 15:03:24 +0000 Subject: [PATCH] BUG: Fix #8510, making MaskedArray.__setitem__ work --- numpy/ma/core.py | 2 +- numpy/ma/tests/test_core.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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']: