summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/ma/core.py12
-rw-r--r--numpy/ma/tests/test_core.py8
2 files changed, 20 insertions, 0 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index ebc335a85..25e542cd6 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -5869,6 +5869,18 @@ class mvoid(MaskedArray):
"""
m = self._mask
+ if isinstance(m[indx], ndarray):
+ # Can happen when indx is a multi-dimensional field:
+ # A = ma.masked_array(data=[([0,1],)], mask=[([True,
+ # False],)], dtype=[("A", ">i2", (2,))])
+ # x = A[0]; y = x["A"]; then y.mask["A"].size==2
+ # and we can not say masked/unmasked.
+ # The result is no longer mvoid!
+ # See also issue #6724.
+ return masked_array(
+ data=self._data[indx], mask=m[indx],
+ fill_value=self._fill_value[indx],
+ hard_mask=self._hardmask)
if m is not nomask and m[indx]:
return masked
return self._data[indx]
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 369138471..cecdedf26 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -719,6 +719,14 @@ class TestMaskedArray(TestCase):
self.assertTrue(f['a'] is masked)
assert_equal(f[1], 4)
+ # exotic dtype
+ A = masked_array(data=[([0,1],)],
+ mask=[([True, False],)],
+ dtype=[("A", ">i2", (2,))])
+ assert_equal(A[0]["A"], A["A"][0])
+ assert_equal(A[0]["A"], masked_array(data=[0, 1],
+ mask=[True, False], dtype=">i2"))
+
def test_mvoid_iter(self):
# Test iteration on __getitem__
ndtype = [('a', int), ('b', int)]