diff options
| author | Eric Wieser <wieser.eric@gmail.com> | 2017-12-28 11:01:35 +0000 |
|---|---|---|
| committer | Eric Wieser <wieser.eric@gmail.com> | 2018-01-01 09:27:22 -0800 |
| commit | 8b1b7f12a53f1a45f5572de3d704d894a60fa1c4 (patch) | |
| tree | 0063467b022959c3f48cd7ce0a5c2e2daec0c9e5 /numpy/ma/core.py | |
| parent | 7bb2d5a8f0219aa5acb5fda05929f1a0745a1883 (diff) | |
| download | numpy-8b1b7f12a53f1a45f5572de3d704d894a60fa1c4.tar.gz | |
BUG: Masked singleton can be reshaped to be non-scalar
It's possible this is the cause of gh-10270, where it seems something is wrong with the shape
Diffstat (limited to 'numpy/ma/core.py')
| -rw-r--r-- | numpy/ma/core.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index fe092f552..f142532db 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -6309,6 +6309,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 |
