summaryrefslogtreecommitdiff
path: root/numpy/ma
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-06-30 21:58:33 +0100
committerEric Wieser <wieser.eric@gmail.com>2017-06-30 21:58:33 +0100
commit7254888b9ffe1f26ce59600ad31b7d4c9135c13d (patch)
treee01683f338865d6f0a724839b1bcca6fff03b841 /numpy/ma
parent4bbbca2dda4099f689a8fb195696062ed783e4ce (diff)
downloadnumpy-7254888b9ffe1f26ce59600ad31b7d4c9135c13d.tar.gz
ENH: Make duplicated masked constants obvious
Diffstat (limited to 'numpy/ma')
-rw-r--r--numpy/ma/core.py6
-rw-r--r--numpy/ma/tests/test_core.py6
2 files changed, 11 insertions, 1 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index ab4364706..2c62019cd 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -6206,7 +6206,11 @@ class MaskedConstant(MaskedArray):
return str(masked_print_option._display)
def __repr__(self):
- return 'masked'
+ if self is masked:
+ return 'masked'
+ else:
+ # something is wrong, make it obvious
+ return object.__repr__(self)
def flatten(self):
return masked_array([self._data], dtype=float, mask=[True])
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 707fcd1de..0a4840d41 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -4732,6 +4732,12 @@ class TestMaskedConstant(TestCase):
assert_(not isinstance(m, np.ma.core.MaskedConstant))
assert_(m is not np.ma.masked)
+ def test_repr(self):
+ # copies should not exist, but if they do, it should be obvious that
+ # something is wrong
+ assert_equal(repr(np.ma.masked), 'masked')
+ assert_not_equal(repr(np.ma.masked.copy()), 'masked')
+
def test_masked_array():
a = np.ma.array([0, 1, 2, 3], mask=[0, 0, 1, 0])