8000 BUG: Fix #8510, making MaskedArray.__setitem__ work · numpy/numpy@10bf55e · GitHub
[go: up one dir, main page]

Skip to content

Commit 10bf55e

Browse files
committed
BUG: Fix #8510, making MaskedArray.__setitem__ work
1 parent 1718ee8 commit 10bf55e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

numpy/ma/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3264,7 +3264,7 @@ def __setitem__(self, indx, value):
32643264
return
32653265

32663266
# Get the _data part of the new value
3267-
dval = value
3267+
dval = getattr(value, '_data', value)
32683268
# Get the _mask part of the new value
32693269
mval = getattr(value, '_mask', nomask)
32703270
if nbfields and mval is nomask:

numpy/ma/tests/test_core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4256,6 +4256,13 @@ def test_setitem(self):
42564256
a[0]['a'] = 2
42574257
assert_equal(a.mask, control)
42584258

4259+
def test_setitem_scalar(self):
4260+
# 8510
4261+
mask_0d = np.ma.masked_array(1, mask=True)
4262+
arr = np.ma.arange(3)
4263+
arr[0] = mask_0d
4264+
assert_array_equal(arr.mask, [True, False, False])
4265+
42594266
def test_element_len(self):
42604267
# check that len() works for mvoid (Github issue #576)
42614268
for rec in self.data['base']:

0 commit comments

Comments
 (0)
0