diff options
Diffstat (limited to 'numpy/ma/core.py')
-rw-r--r-- | numpy/ma/core.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index b76ff8ea9..795e79e00 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -2870,7 +2870,13 @@ class MaskedArray(ndarray): _data._mask = _data._mask.copy() # Reset the shape of the original mask if getmask(data) is not nomask: - data._mask.shape = data.shape + # gh-21022 encounters an issue here + # because data._mask.shape is not writeable, but + # the op was also pointless in that case, because + # the shapes were the same, so we can at least + # avoid that path + if data._mask.shape != data.shape: + data._mask.shape = data.shape else: # Case 2. : With a mask in input. # If mask is boolean, create an array of True or False @@ -6300,6 +6306,13 @@ class MaskedArray(ndarray): memo[id(self)] = copied for (k, v) in self.__dict__.items(): copied.__dict__[k] = deepcopy(v, memo) + # as clearly documented for np.copy(), you need to use + # deepcopy() directly for arrays of object type that may + # contain compound types--you cannot depend on normal + # copy semantics to do the right thing here + if self.dtype.type is np.object_: + for idx, _ in enumerate(copied): + copied[idx] = deepcopy(copied[idx]) return copied |