diff options
author | Marten van Kerkwijk <mhvk@astro.utoronto.ca> | 2014-04-04 17:40:32 -0400 |
---|---|---|
committer | Marten van Kerkwijk <mhvk@astro.utoronto.ca> | 2014-04-04 17:40:32 -0400 |
commit | dfebb5a9a6664148b32444497bb792ecbb2f56f5 (patch) | |
tree | 593f23bc33d0a7b5ada65190ba3d2f4940077781 /numpy | |
parent | 547765dd9b2131e1e8b1ef646d4cc5ba9b4dd791 (diff) | |
download | numpy-dfebb5a9a6664148b32444497bb792ecbb2f56f5.tar.gz |
BUG: Ensure MaskedArray.flat can access single items
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/ma/core.py | 7 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 7 |
2 files changed, 12 insertions, 2 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index d644f5b38..e969abd5e 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -2534,8 +2534,11 @@ class MaskedIterator(object): result = self.dataiter.__getitem__(indx).view(type(self.ma)) if self.maskiter is not None: _mask = self.maskiter.__getitem__(indx) - _mask.shape = result.shape - result._mask = _mask + if isinstance(_mask, ndarray): + _mask.shape = result.shape + result._mask = _mask + elif _mask: + return masked return result ### This won't work is ravel makes a copy diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 7eade7f20..177e5670e 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -1305,6 +1305,11 @@ class TestMaskedArrayAttributes(TestCase): assert_equal(a.mask, nomask) def test_flat(self): + # test simple access + test = masked_array(np.matrix([[1, 2, 3]]), mask=[0, 0, 1]) + assert_equal(test.flat[1], 2) + assert_equal(test.flat[2], masked) + self.assertTrue(np.all(test.flat[0:2] == test[0, 0:2])) # Test flat on masked_matrices test = masked_array(np.matrix([[1, 2, 3]]), mask=[0, 0, 1]) test.flat = masked_array([3, 2, 1], mask=[1, 0, 0]) @@ -1315,6 +1320,8 @@ class TestMaskedArrayAttributes(TestCase): testflat = test.flat testflat[:] = testflat[[2, 1, 0]] assert_equal(test, control) + testflat[0] = 9 + assert_equal(test[0, 0], 9) #------------------------------------------------------------------------------ |