diff options
author | njsmith <njs@pobox.com> | 2012-10-31 11:40:35 -0700 |
---|---|---|
committer | njsmith <njs@pobox.com> | 2012-10-31 11:40:35 -0700 |
commit | 526b7647ad3e0c295340e7b85593364eeadc5686 (patch) | |
tree | 78accc32b1bde59c3b0e6688d17a0f2546e6aee8 | |
parent | a890a8584319c2978735eef96ecaefefacad6346 (diff) | |
parent | 1532b7cce4a296d2fc5a6ef2eea68376c57daa19 (diff) | |
download | numpy-526b7647ad3e0c295340e7b85593364eeadc5686.tar.gz |
Merge pull request #483 from astrofrog/fix-masked-getitem
When accessing MaskedArray rows, always return an mvoid object
-rw-r--r-- | numpy/ma/core.py | 10 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 8 |
2 files changed, 8 insertions, 10 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index a6f252067..a7e04cd13 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -2948,12 +2948,10 @@ class MaskedArray(ndarray): # 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 diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 58f81b071..48ea6e4f9 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -626,7 +626,7 @@ class TestMaskedArray(TestCase): 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 @@ class TestMaskedFields(TestCase): [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 @@ class TestMaskedView(TestCase): 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 @@ class TestMaskedView(TestCase): 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): |