diff options
| -rw-r--r-- | numpy/ma/core.py | 8 | ||||
| -rw-r--r-- | numpy/ma/tests/test_core.py | 2 |
2 files changed, 9 insertions, 1 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index be213ebf3..59ba3a593 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -2835,7 +2835,6 @@ class MaskedArray(ndarray): # Process mask. # Type of the mask mdtype = make_mask_descr(_data.dtype) - if mask is nomask: # Case 1. : no mask in input. # Erase the current mask ? @@ -2870,6 +2869,12 @@ class MaskedArray(ndarray): else: # Case 2. : With a mask in input. # If mask is boolean, create an array of True or False + + # if users pass `mask=None` be forgiving here and cast it False + # for speed; although the default is `mask=nomask` and can differ. + if mask is None: + mask = False + if mask is True and mdtype == MaskType: mask = np.ones(_data.shape, dtype=mdtype) elif mask is False and mdtype == MaskType: @@ -2917,6 +2922,7 @@ class MaskedArray(ndarray): else: _data._mask = np.logical_or(mask, _data._mask) _data._sharedmask = False + # Update fill_value. if fill_value is None: fill_value = getattr(data, '_fill_value', None) diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 028f64c61..bc897d731 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -214,6 +214,8 @@ class TestMaskedArray: assert_(np.may_share_memory(x.mask, y.mask)) y = array([1, 2, 3], mask=x._mask, copy=True) assert_(not np.may_share_memory(x.mask, y.mask)) + x = array([1, 2, 3], mask=None) + assert_equal(x._mask, [False, False, False]) def test_masked_singleton_array_creation_warns(self): # The first works, but should not (ideally), there may be no way |
