summaryrefslogtreecommitdiff
path: root/numpy/ma
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-04-19 18:28:30 +0100
committerEric Wieser <wieser.eric@gmail.com>2017-04-19 23:06:48 +0100
commited75d97949efac09189ddafa165dd7ec875612c1 (patch)
treed4b32d5ba9acb27b352c793865201fb03e8fc602 /numpy/ma
parentc08ec57b08f3342b3063314f1f4bb284aa60b787 (diff)
downloadnumpy-ed75d97949efac09189ddafa165dd7ec875612c1.tar.gz
BUG: Fix __getitem__ on masked arrays containing np.ma.masked
Diffstat (limited to 'numpy/ma')
-rw-r--r--numpy/ma/core.py4
-rw-r--r--numpy/ma/tests/test_core.py16
2 files changed, 19 insertions, 1 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 50a58f86b..8179dc930 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -3244,7 +3244,9 @@ class MaskedArray(ndarray):
return mvoid(dout, mask=mout, hardmask=self._hardmask)
# special case introduced in gh-5962
- elif self.dtype.type is np.object_ and isinstance(dout, np.ndarray):
+ elif (self.dtype.type is np.object_ and
+ isinstance(dout, np.ndarray) and
+ dout is not masked):
# If masked, turn into a MaskedArray, with everything masked.
if mout:
return MaskedArray(dout, mask=True)
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 1bd59d593..35c55894d 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -4471,6 +4471,22 @@ class TestMaskedObjectArray(TestCase):
assert_equal(arr[0,...][()].data, a0)
assert_equal(arr[0,...][()].mask, True)
+ def test_nested_ma(self):
+
+ arr = np.ma.array([None, None])
+ # set the first object to be an unmasked masked constant. A little fiddly
+ arr[0,...] = np.array([np.ma.masked], object)[0,...]
+
+ # check the above line did what we were aiming for
+ assert_(arr.data[0] is np.ma.masked)
+
+ # test that getitem returned the value by identity
+ assert_(arr[0] is np.ma.masked)
+
+ # now mask the masked value!
+ arr[0] = np.ma.masked
+ assert_(arr[0] is np.ma.masked)
+
class TestMaskedView(TestCase):