summaryrefslogtreecommitdiff
path: root/numpy/ma
diff options
context:
space:
mode:
authorStefan van der Walt <stefan@sun.ac.za>2007-12-21 08:33:02 +0000
committerStefan van der Walt <stefan@sun.ac.za>2007-12-21 08:33:02 +0000
commit11c95e35e85166b808ea24d321f86a7bc4a0dcab (patch)
tree272101e8bf9fee1e3ceb89efe36d03c1b96e0b8d /numpy/ma
parentc9fe4c3bf9eb239d13173a55b530c1349e22835d (diff)
downloadnumpy-11c95e35e85166b808ea24d321f86a7bc4a0dcab.tar.gz
Fix unit tests. Prevent nomask from being copied.
Diffstat (limited to 'numpy/ma')
-rw-r--r--numpy/ma/core.py16
-rw-r--r--numpy/ma/tests/test_core.py15
-rw-r--r--numpy/ma/tests/test_old_ma.py11
3 files changed, 30 insertions, 12 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 12d84975a..6bece6e52 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -76,15 +76,27 @@ from numpy import expand_dims as n_expand_dims
from numpy import array as narray
import warnings
+class NoMask(ndarray):
+ def __new__(subtype):
+ narray(False)
+ return narray(False).view(subtype)
+
+ def no_op(self,*args,**kwargs):
+ return self
+
+ def __array_finalize__(self,obj):
+ obj.flags['WRITEABLE'] = False
+
+ def copy(self):
+ return self
MaskType = bool_
-nomask = narray(False)
+nomask = NoMask()
divide_tolerance = 1.e-35
numpy.seterr(all='ignore')
-
#####--------------------------------------------------------------------------
#---- --- Exceptions ---
#####--------------------------------------------------------------------------
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index d8caaaf6c..48e8682ce 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -29,6 +29,18 @@ pi = numpy.pi
from test_old_ma import *
+class TestNoMask(NumpyTestCase):
+ def test_no_inplace(self):
+ x = nomask
+ def iadd(x):
+ x += 1
+ self.failUnlessRaises(ValueError,iadd,x)
+
+ def test_no_copy(self):
+ x = nomask
+ y = x.copy()
+ assert x is y
+
#..............................................................................
class TestMA(NumpyTestCase):
"Base test class for MaskedArrays."
@@ -1304,10 +1316,9 @@ class TestArrayMethods(NumpyTestCase):
assert(data.squeeze() is masked)
def check_putmask(self):
- x = numpy.arange(6)+1
+ x = arange(6)+1
mx = array(x, mask=[0,0,0,1,1,1])
mask = [0,0,1,0,0,1]
-
# w/o mask, w/o masked values
xx = x.copy()
putmask(xx, mask, 99)
diff --git a/numpy/ma/tests/test_old_ma.py b/numpy/ma/tests/test_old_ma.py
index 41be92011..c2da8b3f3 100644
--- a/numpy/ma/tests/test_old_ma.py
+++ b/numpy/ma/tests/test_old_ma.py
@@ -304,10 +304,8 @@ class TestMa(NumpyTestCase):
(x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d
m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]
i = numpy.nonzero(m)[0]
- putmask(xm, m, z)
- assert all(take(xm, i, axis=0) == z)
put(ym, i, zm)
- assert take(ym, i, axis=0) == zm
+ assert all(take(ym, i, axis=0) == zm)
def check_testOddFeatures(self):
"Test of other odd features"
@@ -584,11 +582,8 @@ class TestMa(NumpyTestCase):
self.assertEqual(1, int(array([[[1]]])))
self.assertEqual(1.0, float(array([[1]])))
self.failUnlessRaises(ValueError, float, array([1,1]))
- self.failUnlessRaises(MAError, float, array([1],mask=[1]))
- self.failUnless(bool(array([0,1])))
- self.failUnless(bool(array([0,0],mask=[0,1])))
- self.failIf(bool(array([0,0])))
- self.failIf(bool(array([0,0],mask=[0,0])))
+ self.failUnlessRaises(ValueError, bool, array([0,1]))
+ self.failUnlessRaises(ValueError, bool, array([0,0],mask=[0,1]))
def check_testScalarArithmetic(self):
xm = array(0, mask=1)