summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2014-03-26 20:33:38 -0600
committerCharles Harris <charlesr.harris@gmail.com>2014-03-26 20:33:38 -0600
commit46767a2ffc6bf7b3c6841bd9b10f1f26543d22b7 (patch)
treef3078d9e2951f9cb65442e774c3b0e23b514e3e1 /numpy
parent69238dd8c223e447a42eac8a9ed10a0662dcdbef (diff)
parenta49c2797c84825e397de1a5dea4daf0b6db3f160 (diff)
downloadnumpy-46767a2ffc6bf7b3c6841bd9b10f1f26543d22b7.tar.gz
Merge pull request #4045 from abalkin/gh-4043
ENH: ma.asarray() and ma.asanyarray() will pass through input of the cor...
Diffstat (limited to 'numpy')
-rw-r--r--numpy/ma/core.py4
-rw-r--r--numpy/ma/extras.py4
-rw-r--r--numpy/ma/tests/test_core.py15
3 files changed, 20 insertions, 3 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 34272d4cf..9c3c6a615 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -7002,6 +7002,8 @@ def asarray(a, dtype=None, order=None):
<class 'numpy.ma.core.MaskedArray'>
"""
+ if dtype is None and type(a) is MaskedArray:
+ return a
return masked_array(a, dtype=dtype, copy=False, keep_mask=True, subok=False)
def asanyarray(a, dtype=None):
@@ -7047,6 +7049,8 @@ def asanyarray(a, dtype=None):
<class 'numpy.ma.core.MaskedArray'>
"""
+ if dtype is None and isinstance(a, MaskedArray):
+ return a
return masked_array(a, dtype=dtype, copy=False, keep_mask=True, subok=True)
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py
index c2d105584..7182bf4ae 100644
--- a/numpy/ma/extras.py
+++ b/numpy/ma/extras.py
@@ -842,9 +842,9 @@ def mask_rowcols(a, axis=None):
fill_value=999999)
"""
- a = asarray(a)
+ a = array(a, subok=False)
if a.ndim != 2:
- raise NotImplementedError("compress2d works for 2D arrays only.")
+ raise NotImplementedError("mask_rowcols works for 2D arrays only.")
m = getmask(a)
# Nothing is masked: return a
if m is nomask or not m.any():
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 8cc973d09..b9b84d7b2 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -186,11 +186,24 @@ class TestMaskedArray(TestCase):
(x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
xm.fill_value = -9999
xm._hardmask = True
- xmm = asarray(xm)
+ xmm = asarray(xm, xm.dtype)
assert_equal(xmm._data, xm._data)
assert_equal(xmm._mask, xm._mask)
assert_equal(xmm.fill_value, xm.fill_value)
assert_equal(xmm._hardmask, xm._hardmask)
+ # address gh-4043
+ self.assertTrue(xm is asarray(xm))
+
+ def test_asanyarray(self):
+ class M(MaskedArray):
+ pass
+ xm = M([])
+ self.assertTrue(xm is not asarray(xm))
+ # address gh-4043
+ self.assertTrue(xm is asanyarray(xm))
+ test = asanyarray(xm, np.int64)
+ self.assertTrue(isinstance(test, M))
+ assert_equal(test.dtype, np.int64)
def test_fix_invalid(self):
# Checks fix_invalid.