From 7254888b9ffe1f26ce59600ad31b7d4c9135c13d Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Fri, 30 Jun 2017 21:58:33 +0100 Subject: ENH: Make duplicated masked constants obvious --- numpy/ma/core.py | 6 +++++- numpy/ma/tests/test_core.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'numpy/ma') 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]) -- cgit v1.2.1