summaryrefslogtreecommitdiff
path: root/numpy/ma/core.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2018-01-01 18:08:28 -0700
committerGitHub <noreply@github.com>2018-01-01 18:08:28 -0700
commitdd866e3eb0371103fc30dffd743953bd927033a2 (patch)
treee5b0ffdce25b5db9eed0b3dff4247f0587350a60 /numpy/ma/core.py
parent5acb9b3c18cb8001ef30635b7aae69fb12152395 (diff)
parent8b1b7f12a53f1a45f5572de3d704d894a60fa1c4 (diff)
downloadnumpy-dd866e3eb0371103fc30dffd743953bd927033a2.tar.gz
Merge pull request #10292 from eric-wieser/no-change-masked-shape
BUG: Masked singleton can be reshaped to be non-scalar
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