summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/ma/core.py16
-rw-r--r--numpy/ma/tests/test_core.py12
2 files changed, 24 insertions, 4 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 392e91ec1..7a11e1eb6 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -1225,11 +1225,19 @@ class MaskedArray(ndarray):
# With full version
else:
_data._mask = np.zeros(_data.shape, dtype=mdtype)
- if copy:
- _data._mask = _data._mask.copy()
- _data._sharedmask = False
+ # Check whether we missed something
+ elif isinstance(data, (tuple,list)):
+ mask = np.array([getmaskarray(m) for m in data], dtype=mdtype)
+ # Force shrinking of the mask if needed (and possible)
+ if (mdtype == MaskType) and mask.any():
+ _data._mask = mask
+ _data._sharedmask = False
else:
- _data._sharedmask = True
+ if copy:
+ _data._mask = _data._mask.copy()
+ _data._sharedmask = False
+ else:
+ _data._sharedmask = True
# Case 2. : With a mask in input ........
else:
# Read the mask with the current mdtype
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index fd3395188..4558777dd 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -167,6 +167,18 @@ class TestMaskedArray(NumpyTestCase):
dma_3 = MaskedArray(dma_1, mask=[1,0,0,0]*6)
fail_if_equal(dma_3.mask, dma_1.mask)
+ def test_creation_with_list_of_maskedarrays(self):
+ "Tests creaating a masked array from alist of masked arrays."
+ x = array(np.arange(5), mask=[1,0,0,0,0])
+ data = array((x,x[::-1]))
+ assert_equal(data, [[0,1,2,3,4],[4,3,2,1,0]])
+ assert_equal(data._mask, [[1,0,0,0,0],[0,0,0,0,1]])
+ #
+ x.mask = nomask
+ data = array((x,x[::-1]))
+ assert_equal(data, [[0,1,2,3,4],[4,3,2,1,0]])
+ assert(data.mask is nomask)
+
def test_asarray(self):
(x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
xm.fill_value = -9999