summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/ma/core.py6
-rw-r--r--numpy/ma/tests/test_core.py8
2 files changed, 14 insertions, 0 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index b4f08171a..c8664c754 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -1229,6 +1229,9 @@ class MaskedArray(ndarray):
_data = np.array(data, dtype=dtype, copy=copy, subok=True, ndmin=ndmin)
_baseclass = getattr(data, '_baseclass', type(_data))
_optinfo = {}
+ # Check that we'ew not erasing the mask..........
+ if isinstance(data,MaskedArray) and (data.shape != _data.shape):
+ copy = True
# Careful, cls might not always be MaskedArray...
if not isinstance(data, cls) or not subok:
_data = _data.view(cls)
@@ -1267,6 +1270,9 @@ class MaskedArray(ndarray):
if copy:
_data._mask = _data._mask.copy()
_data._sharedmask = False
+ # Reset the shape of the original mask
+ if getmask(data) is not nomask:
+ data._mask.shape = data.shape
else:
_data._sharedmask = True
# Case 2. : With a mask in input ........
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index e581e274e..e24fa6f54 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -139,6 +139,14 @@ class TestMaskedArray(TestCase):
assert_equal(x._data,[[1,2,3]])
assert_equal(x._mask,[[1,0,0]])
+ def test_creation_ndmin_from_maskedarray(self):
+ "Make sure we're not losing the original mask w/ ndmin"
+ x = array([1,2,3])
+ x[-1] = masked
+ xx = array(x, ndmin=2, dtype=float)
+ assert_equal(x.shape, x._mask.shape)
+ assert_equal(xx.shape, xx._mask.shape)
+
def test_creation_maskcreation(self):
"Tests how masks are initialized at the creation of Maskedarrays."
data = arange(24, dtype=float)