summaryrefslogtreecommitdiff
path: root/numpy/ma
diff options
context:
space:
mode:
authorKritika Jalan <krithi710@gmail.com>2018-05-26 11:21:33 +0530
committerEric Wieser <wieser.eric@gmail.com>2018-05-25 22:51:33 -0700
commitc1fc882277bcec42e11f67c6eced43d68cec4d7a (patch)
tree943318523efd2998fe4581c0a4652ea684cb2493 /numpy/ma
parent0bd86db79b7a8000f9dbd401df722ffae9c2b33c (diff)
downloadnumpy-c1fc882277bcec42e11f67c6eced43d68cec4d7a.tar.gz
BUG: __copy__ and __deepcopy__ should preserve MaskedConstant (#11038)
Fixes #11021
Diffstat (limited to 'numpy/ma')
-rw-r--r--numpy/ma/core.py6
-rw-r--r--numpy/ma/tests/test_core.py10
2 files changed, 16 insertions, 0 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index fb28fa8e5..c0dda6f31 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -6317,6 +6317,12 @@ class MaskedConstant(MaskedArray):
# precedent for this with `np.bool_` scalars.
return self
+ def __copy__(self):
+ return self
+
+ def __deepcopy__(self, memo):
+ return self
+
def __setattr__(self, attr, value):
if not self.__has_singleton():
# allow the singleton to be initialized
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 63703f6cd..4c7440aab 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -4826,6 +4826,16 @@ class TestMaskedConstant(object):
np.ma.masked.copy() is np.ma.masked,
np.True_.copy() is np.True_)
+ def test__copy(self):
+ import copy
+ assert_(
+ copy.copy(np.ma.masked) is np.ma.masked)
+
+ def test_deepcopy(self):
+ import copy
+ assert_(
+ copy.deepcopy(np.ma.masked) is np.ma.masked)
+
def test_immutable(self):
orig = np.ma.masked
assert_raises(np.ma.core.MaskError, operator.setitem, orig, (), 1)