diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2015-12-01 16:22:31 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2015-12-01 16:22:31 -0700 |
commit | b3a8994a2a3c89c00ac4a95e01cd0888b72fd9af (patch) | |
tree | 3607aa1c95a9f0edf89d0de30e2041ff8db7e7b1 /numpy/ma/core.py | |
parent | 11f809219458973d73018ad2438cb8514b61c7a6 (diff) | |
parent | 511dab48438dcc9470b5632e206eeef74f5ad6bc (diff) | |
download | numpy-b3a8994a2a3c89c00ac4a95e01cd0888b72fd9af.tar.gz |
Merge pull request #6734 from saimn/ma-mask-memory
ENH: Avoid memory peak when creating a MaskedArray with mask=True/False.
Diffstat (limited to 'numpy/ma/core.py')
-rw-r--r-- | numpy/ma/core.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index f6e445c2f..9cc1a1272 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -2758,13 +2758,19 @@ class MaskedArray(ndarray): _data._sharedmask = True else: # Case 2. : With a mask in input. - # Read the mask with the current mdtype - try: - mask = np.array(mask, copy=copy, dtype=mdtype) - # Or assume it's a sequence of bool/int - except TypeError: - mask = np.array([tuple([m] * len(mdtype)) for m in mask], - dtype=mdtype) + # If mask is boolean, create an array of True or False + if mask is True and mdtype == MaskType: + mask = np.ones(_data.shape, dtype=mdtype) + elif mask is False and mdtype == MaskType: + mask = np.zeros(_data.shape, dtype=mdtype) + else: + # Read the mask with the current mdtype + try: + mask = np.array(mask, copy=copy, dtype=mdtype) + # Or assume it's a sequence of bool/int + except TypeError: + mask = np.array([tuple([m] * len(mdtype)) for m in mask], + dtype=mdtype) # Make sure the mask and the data have the same shape if mask.shape != _data.shape: (nd, nm) = (_data.size, mask.size) |