summaryrefslogtreecommitdiff
path: root/numpy/ma/core.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/ma/core.py')
-rw-r--r--numpy/ma/core.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 0f4cff14b..69f01b819 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -6313,6 +6313,18 @@ class MaskedConstant(MaskedArray):
# precedent for this with `np.bool_` scalars.
return self
+ def __setattr__(self, attr, value):
+ if not self.__has_singleton():
+ # allow the singleton to be initialized
+ return super(MaskedConstant, self).__setattr__(attr, value)
+ elif self is self.__singleton:
+ raise AttributeError(
+ "attributes of {!r} are not writeable".format(self))
+ else:
+ # duplicate instance - we can end up here from __array_finalize__,
+ # where we set the __class__ attribute
+ return super(MaskedConstant, self).__setattr__(attr, value)
+
masked = masked_singleton = MaskedConstant()
masked_array = MaskedArray