summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>2017-02-20 15:39:07 -0500
committerGitHub <noreply@github.com>2017-02-20 15:39:07 -0500
commitb8769a21cddc2ded3c140dd0f6b1d744caadacd1 (patch)
tree20ab82a0ac67352d0fe0e255a642fd3a52d110cb
parent60ad1ec509ba719e21a69282e49b67de381465a7 (diff)
parent10bf55e6548e970481baf7b333aeab20743e5b3b (diff)
downloadnumpy-b8769a21cddc2ded3c140dd0f6b1d744caadacd1.tar.gz
Merge pull request #8594 from eric-wieser/MaskedArray.__setitem__
BUG: Fix MaskedArray.__setitem__
-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 568087613..a6f474b95 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -3266,7 +3266,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 = getmask(value)
if nbfields and mval is nomask:
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 2b491b47e..f72ddc5ea 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -4255,6 +4255,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']: