Skip to content

When accessing MaskedArray rows, always return an mvoid object #483

Merged
merged 2 commits into from Oct 31, 2012
View
10 numpy/ma/core.py
@@ -2948,12 +2948,10 @@ def __getitem__(self, indx):
# A record ................
if isinstance(dout, np.void):
mask = _mask[indx]
-# If we can make mvoid a subclass of np.void, that'd be what we'd need
-# return mvoid(dout, mask=mask)
- if flatten_mask(mask).any():
- dout = mvoid(dout, mask=mask)
- else:
- return dout
+ # We should always re-cast to mvoid, otherwise users can
+ # change masks on rows that already have masked values, but not
+ # on rows that have no masked values, which is inconsistent.
+ dout = mvoid(dout, mask=mask)
# Just a scalar............
elif _mask is not nomask and _mask[indx]:
return masked
View
8 numpy/ma/tests/test_core.py
@@ -626,7 +626,7 @@ def test_mvoid_getitem(self):
a = masked_array([(1, 2,), (3, 4)], mask=[(0, 0), (1, 0)], dtype=ndtype)
# w/o mask
f = a[0]
- self.assertTrue(isinstance(f, np.void))
+ self.assertTrue(isinstance(f, mvoid))
assert_equal((f[0], f['a']), (1, 1))
assert_equal(f['b'], 2)
# w/ mask
@@ -3443,7 +3443,7 @@ def test_getitem(self):
[1, 0, 0, 0, 0, 0, 0, 0, 1, 0]),
dtype=[('a', bool), ('b', bool)])
# No mask
- self.assertTrue(isinstance(a[1], np.void))
+ self.assertTrue(isinstance(a[1], MaskedArray))
# One element masked
self.assertTrue(isinstance(a[0], MaskedArray))
assert_equal_records(a[0]._data, a._data[0])
@@ -3503,7 +3503,7 @@ def test_view_to_flexible_dtype(self):
assert_equal(test['B'], a['b'][0])
#
test = a[-1].view([('A', float), ('B', float)])
- self.assertTrue(not isinstance(test, MaskedArray))
+ self.assertTrue(isinstance(test, MaskedArray))
assert_equal(test.dtype.names, ('A', 'B'))
assert_equal(test['A'], a['a'][-1])
assert_equal(test['B'], a['b'][-1])
@@ -3523,7 +3523,7 @@ def test_view_to_subdtype(self):
assert_equal(test.mask, (1, 0))
# View on 1 unmasked element
test = a[-1].view((float, 2))
- self.assertTrue(not isinstance(test, MaskedArray))
+ self.assertTrue(isinstance(test, MaskedArray))
assert_equal(test, data[-1])
#
def test_view_to_dtype_and_type(self):
Something went wrong with that request. Please try again.