summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorrgommers <ralf.gommers@googlemail.com>2011-03-07 10:24:03 +0800
committerrgommers <ralf.gommers@googlemail.com>2011-03-11 12:27:02 +0800
commitceb9ded475887c25299d798ac90094b74d593a61 (patch)
tree868dbe7855fa58b3408cfe4d6dc0549c987aa57f /numpy
parent083f6e1933dc244db6a97b49830071be6aa6555c (diff)
downloadnumpy-ceb9ded475887c25299d798ac90094b74d593a61.tar.gz
DEP: remove deprecated items from ma/core.py
The following are removed: - MaskedArray.raw_data method - MaskedArray flag keyword - make_mask flag keyword - allclose fill_value keyword Also change some assert's to assert_().
Diffstat (limited to 'numpy')
-rw-r--r--numpy/ma/core.py49
-rw-r--r--numpy/ma/tests/test_core.py132
2 files changed, 68 insertions, 113 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 48ed424ff..936df17f3 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -1419,7 +1419,7 @@ def is_mask(m):
except AttributeError:
return False
-def make_mask(m, copy=False, shrink=True, flag=None, dtype=MaskType):
+def make_mask(m, copy=False, shrink=True, dtype=MaskType):
"""
Create a boolean mask from an array.
@@ -1436,8 +1436,6 @@ def make_mask(m, copy=False, shrink=True, flag=None, dtype=MaskType):
Whether to return a copy of `m` (True) or `m` itself (False).
shrink : bool, optional
Whether to shrink `m` to ``nomask`` if all its values are False.
- flag : bool, optional
- Deprecated equivalent of `shrink`.
dtype : dtype, optional
Data-type of the output mask. By default, the output mask has
a dtype of MaskType (bool). If the dtype is flexible, each field
@@ -1491,10 +1489,6 @@ def make_mask(m, copy=False, shrink=True, flag=None, dtype=MaskType):
dtype=[('man', '|b1'), ('mouse', '|b1')])
"""
- if flag is not None:
- warnings.warn("The flag 'flag' is now called 'shrink'!",
- DeprecationWarning)
- shrink = flag
if m is nomask:
return nomask
elif isinstance(m, ndarray):
@@ -2582,7 +2576,7 @@ class MaskedArray(ndarray):
x = MaskedArray(data, mask=nomask, dtype=None,
copy=False, subok=True, ndmin=0, fill_value=None,
- keep_mask=True, hard_mask=None, flag=None, shrink=True)
+ keep_mask=True, hard_mask=None, shrink=True)
Parameters
----------
@@ -2625,7 +2619,7 @@ class MaskedArray(ndarray):
def __new__(cls, data=None, mask=nomask, dtype=None, copy=False,
subok=True, ndmin=0, fill_value=None,
- keep_mask=True, hard_mask=None, flag=None, shrink=True,
+ keep_mask=True, hard_mask=None, shrink=True,
**options):
"""
Create a new masked array from scratch.
@@ -2635,10 +2629,6 @@ class MaskedArray(ndarray):
A masked array can also be created by taking a .view(MaskedArray).
"""
- if flag is not None:
- warnings.warn("The flag 'flag' is now called 'shrink'!",
- DeprecationWarning)
- shrink = flag
# Process data............
_data = np.array(data, dtype=dtype, copy=copy, subok=True, ndmin=ndmin)
_baseclass = getattr(data, '_baseclass', type(_data))
@@ -3258,27 +3248,6 @@ class MaskedArray(ndarray):
_data = property(fget=_get_data)
data = property(fget=_get_data)
- def raw_data(self):
- """
- Return the data part of the masked array.
-
- DEPRECATED: You should really use ``.data`` instead.
-
- Examples
- --------
- >>> x = np.ma.array([1, 2, 3], mask=[False, True, False])
- >>> x
- masked_array(data = [1 -- 3],
- mask = [False True False],
- fill_value = 999999)
- >>> x.data
- array([1, 2, 3])
-
- """
- warnings.warn('Use .data instead.', DeprecationWarning)
- return self._data
-
-
def _get_flat(self):
"Return a flat iterator."
return MaskedIterator(self)
@@ -5025,7 +4994,7 @@ class MaskedArray(ndarray):
>>> a.sort(endwith=False, fill_value=3)
>>> print a
[1 -- -- 3 5]
-
+
"""
if self._mask is nomask:
ndarray.sort(self, axis=axis, kind=kind, order=order)
@@ -6798,7 +6767,7 @@ def allequal (a, b, fill_value=True):
else:
return False
-def allclose (a, b, masked_equal=True, rtol=1e-5, atol=1e-8, fill_value=None):
+def allclose (a, b, masked_equal=True, rtol=1e-5, atol=1e-8):
"""
Returns True if two arrays are element-wise equal within a tolerance.
@@ -6819,9 +6788,6 @@ def allclose (a, b, masked_equal=True, rtol=1e-5, atol=1e-8, fill_value=None):
atol : float, optional
Absolute tolerance. The absolute difference is equal to `atol`.
Default is 1e-8.
- fill_value : bool, optional
- *Deprecated* - Whether masked values in `a` or `b` are considered equal
- (True) or not (False).
Returns
-------
@@ -6873,11 +6839,6 @@ def allclose (a, b, masked_equal=True, rtol=1e-5, atol=1e-8, fill_value=None):
False
"""
- if fill_value is not None:
- warnings.warn("The use of fill_value is deprecated."\
- " Please use masked_equal instead.")
- masked_equal = fill_value
- #
x = masked_array(a, copy=False)
y = masked_array(b, copy=False)
m = mask_or(getmask(x), getmask(y))
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index c55559001..070701089 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -243,9 +243,9 @@ class TestMaskedArray(TestCase):
junk, garbage = str(x2), repr(x2)
assert_equal(np.sort(x1), sort(x2, endwith=False))
# tests of indexing
- assert type(x2[1]) is type(x1[1])
- assert x1[1] == x2[1]
- assert x2[0] is masked
+ assert_(type(x2[1]) is type(x1[1]))
+ assert_(x1[1] == x2[1])
+ assert_(x2[0] is masked)
assert_equal(x1[2], x2[2])
assert_equal(x1[2:5], x2[2:5])
assert_equal(x1[:], x2[:])
@@ -262,16 +262,16 @@ class TestMaskedArray(TestCase):
assert_equal(x1, x2)
x2[:] = x1
x2[1] = masked
- assert allequal(getmask(x2), array([0, 1, 0, 0]))
+ assert_(allequal(getmask(x2), array([0, 1, 0, 0])))
x3[:] = masked_array([1, 2, 3, 4], [0, 1, 1, 0])
- assert allequal(getmask(x3), array([0, 1, 1, 0]))
+ assert_(allequal(getmask(x3), array([0, 1, 1, 0])))
x4[:] = masked_array([1, 2, 3, 4], [0, 1, 1, 0])
- assert allequal(getmask(x4), array([0, 1, 1, 0]))
- assert allequal(x4, array([1, 2, 3, 4]))
+ assert_(allequal(getmask(x4), array([0, 1, 1, 0])))
+ assert_(allequal(x4, array([1, 2, 3, 4])))
x1 = np.arange(5) * 1.0
x2 = masked_values(x1, 3.0)
assert_equal(x1, x2)
- assert allequal(array([0, 0, 0, 1, 0], MaskType), x2.mask)
+ assert_(allequal(array([0, 0, 0, 1, 0], MaskType), x2.mask))
assert_equal(3.0, x2.fill_value)
x1 = array([1, 'hello', 2, 3], object)
x2 = np.array([1, 'hello', 2, 3], object)
@@ -280,7 +280,7 @@ class TestMaskedArray(TestCase):
assert_equal(type(s2), str)
assert_equal(type(s1), str)
assert_equal(s1, s2)
- assert x1[1:1].shape == (0,)
+ assert_(x1[1:1].shape == (0,))
def test_copy(self):
@@ -292,23 +292,19 @@ class TestMaskedArray(TestCase):
m3 = make_mask(m, copy=1)
self.assertTrue(m is not m3)
- warnings.simplefilter('ignore', DeprecationWarning)
x1 = np.arange(5)
y1 = array(x1, mask=m)
#self.assertTrue( y1._data is x1)
assert_equal(y1._data.__array_interface__, x1.__array_interface__)
- self.assertTrue(allequal(x1, y1.raw_data()))
+ self.assertTrue(allequal(x1, y1.data))
#self.assertTrue( y1.mask is m)
assert_equal(y1._mask.__array_interface__, m.__array_interface__)
- warnings.simplefilter('default', DeprecationWarning)
y1a = array(y1)
- #self.assertTrue( y1a.raw_data() is y1.raw_data())
self.assertTrue(y1a._data.__array_interface__ == y1._data.__array_interface__)
self.assertTrue(y1a.mask is y1.mask)
y2 = array(x1, mask=m)
- #self.assertTrue( y2.raw_data() is x1)
self.assertTrue(y2._data.__array_interface__ == x1.__array_interface__)
#self.assertTrue( y2.mask is m)
self.assertTrue(y2._mask.__array_interface__ == m.__array_interface__)
@@ -431,7 +427,7 @@ class TestMaskedArray(TestCase):
self.assertRaises(TypeError, float, array([1, 1]))
#
warnings.simplefilter('ignore', UserWarning)
- assert np.isnan(float(array([1], mask=[1])))
+ assert_(np.isnan(float(array([1], mask=[1]))))
warnings.simplefilter('default', UserWarning)
#
a = array([1, 2, 3], mask=[1, 0, 0])
@@ -448,7 +444,7 @@ class TestMaskedArray(TestCase):
x = arange(20)
x = x.reshape(4, 5)
x.flat[5] = 12
- assert x[1, 0] == 12
+ assert_(x[1, 0] == 12)
z = x + 10j * x
assert_equal(z.real, x)
assert_equal(z.imag, 10 * x)
@@ -457,18 +453,18 @@ class TestMaskedArray(TestCase):
#
x = arange(10)
x[3] = masked
- assert str(x[3]) == str(masked)
+ assert_(str(x[3]) == str(masked))
c = x >= 8
- assert count(where(c, masked, masked)) == 0
- assert shape(where(c, masked, masked)) == c.shape
+ assert_(count(where(c, masked, masked)) == 0)
+ assert_(shape(where(c, masked, masked)) == c.shape)
#
z = masked_where(c, x)
- assert z.dtype is x.dtype
- assert z[3] is masked
- assert z[4] is not masked
- assert z[7] is not masked
- assert z[8] is masked
- assert z[9] is masked
+ assert_(z.dtype is x.dtype)
+ assert_(z[3] is masked)
+ assert_(z[4] is not masked)
+ assert_(z[7] is not masked)
+ assert_(z[8] is masked)
+ assert_(z[9] is masked)
assert_equal(x, z)
@@ -482,9 +478,9 @@ class TestMaskedArray(TestCase):
c[0] = masked
z = where(c, x, -x)
assert_equal(z, [1., 2., 0., -4., -5])
- assert z[0] is masked
- assert z[1] is not masked
- assert z[2] is masked
+ assert_(z[0] is masked)
+ assert_(z[1] is not masked)
+ assert_(z[2] is masked)
def test_oddfeatures_3(self):
@@ -769,7 +765,7 @@ class TestMaskedArrayArithmetic(TestCase):
assert_equal(y.shape, x.shape)
assert_equal(y._mask, [True, True])
y = x[0] * masked
- assert y is masked
+ assert_(y is masked)
y = x + masked
assert_equal(y.shape, x.shape)
assert_equal(y._mask, [True, True])
@@ -830,13 +826,13 @@ class TestMaskedArrayArithmetic(TestCase):
assert_equal(1, count(1))
assert_equal(0, array(1, mask=[1]))
ott = ott.reshape((2, 2))
- assert isinstance(count(ott, 0), ndarray)
+ assert_(isinstance(count(ott, 0), ndarray))
if sys.version_info[0] >= 3:
- assert isinstance(count(ott), np.integer)
+ assert_(isinstance(count(ott), np.integer))
else:
- assert isinstance(count(ott), types.IntType)
+ assert_(isinstance(count(ott), types.IntType))
assert_equal(3, count(ott))
- assert getmask(count(ott, 0)) is nomask
+ assert_(getmask(count(ott, 0)) is nomask)
assert_equal([1, 2], count(ott, 0))
@@ -856,8 +852,8 @@ class TestMaskedArrayArithmetic(TestCase):
y[0] = masked
assert_equal(minimum(x, y), where(less(x, y), x, y))
assert_equal(maximum(x, y), where(greater(x, y), x, y))
- assert minimum(x) == 0
- assert maximum(x) == 4
+ assert_(minimum(x) == 0)
+ assert_(maximum(x) == 4)
#
x = arange(4).reshape(2, 2)
x[-1, -1] = masked
@@ -1076,9 +1072,9 @@ class TestMaskedArrayArithmetic(TestCase):
y = array(['abc', 1, 'def', 2, 3], object)
y[2] = masked
t = take(y, [0, 3, 4])
- assert t[0] == 'abc'
- assert t[1] == 2
- assert t[2] == 3
+ assert_(t[0] == 'abc')
+ assert_(t[1] == 2)
+ assert_(t[2] == 3)
def test_imag_real(self):
@@ -1640,13 +1636,11 @@ class TestMaskedArrayInPlaceArithmetics(TestCase):
xm += 1
assert_equal(xm, y + 1)
#
- warnings.simplefilter('ignore', DeprecationWarning)
(x, _, xm) = self.floatdata
- id1 = x.raw_data().ctypes._data
+ id1 = x.data.ctypes._data
x += 1.
- assert (id1 == x.raw_data().ctypes._data)
+ assert_(id1 == x.data.ctypes._data)
assert_equal(x, y + 1.)
- warnings.simplefilter('default', DeprecationWarning)
def test_inplace_addition_array(self):
"""Test of inplace additions"""
@@ -1996,15 +1990,15 @@ class TestMaskedArrayMethods(TestCase):
mxbig = (mx > 0.5)
mxsmall = (mx < 0.5)
#
- assert (mxbig.all() == False)
- assert (mxbig.any() == True)
+ assert_((mxbig.all() == False))
+ assert_((mxbig.any() == True))
assert_equal(mxbig.all(0), [False, False, True])
assert_equal(mxbig.all(1), [False, False, True])
assert_equal(mxbig.any(0), [False, False, True])
assert_equal(mxbig.any(1), [True, True, True])
#
- assert (mxsmall.all() == False)
- assert (mxsmall.any() == True)
+ assert_((mxsmall.all() == False))
+ assert_((mxsmall.any() == True))
assert_equal(mxsmall.all(0), [True, True, False])
assert_equal(mxsmall.all(1), [False, False, False])
assert_equal(mxsmall.any(0), [True, True, False])
@@ -2023,15 +2017,15 @@ class TestMaskedArrayMethods(TestCase):
mXbig = (mX > 0.5)
mXsmall = (mX < 0.5)
#
- assert (mXbig.all() == False)
- assert (mXbig.any() == True)
+ assert_((mXbig.all() == False))
+ assert_((mXbig.any() == True))
assert_equal(mXbig.all(0), np.matrix([False, False, True]))
assert_equal(mXbig.all(1), np.matrix([False, False, True]).T)
assert_equal(mXbig.any(0), np.matrix([False, False, True]))
assert_equal(mXbig.any(1), np.matrix([ True, True, True]).T)
#
- assert (mXsmall.all() == False)
- assert (mXsmall.any() == True)
+ assert_((mXsmall.all() == False))
+ assert_((mXsmall.any() == True))
assert_equal(mXsmall.all(0), np.matrix([True, True, False]))
assert_equal(mXsmall.all(1), np.matrix([False, False, False]).T)
assert_equal(mXsmall.any(0), np.matrix([True, True, False]))
@@ -2942,9 +2936,9 @@ class TestMaskedArrayFunctions(TestCase):
c[0] = masked
z = where(c, x, -x)
assert_equal(z, [1., 2., 0., -4., -5])
- assert z[0] is masked
- assert z[1] is not masked
- assert z[2] is masked
+ assert_(z[0] is masked)
+ assert_(z[1] is not masked)
+ assert_(z[2] is masked)
def test_round_with_output(self):
@@ -3065,21 +3059,21 @@ class TestMaskedArrayFunctions(TestCase):
c = x >= 8
# Set False to masked
z = where(c , x, masked)
- assert z.dtype is x.dtype
- assert z[3] is masked
- assert z[4] is masked
- assert z[7] is masked
- assert z[8] is not masked
- assert z[9] is not masked
+ assert_(z.dtype is x.dtype)
+ assert_(z[3] is masked)
+ assert_(z[4] is masked)
+ assert_(z[7] is masked)
+ assert_(z[8] is not masked)
+ assert_(z[9] is not masked)
assert_equal(x, z)
# Set True to masked
z = where(c , masked, x)
- assert z.dtype is x.dtype
- assert z[3] is masked
- assert z[4] is not masked
- assert z[7] is not masked
- assert z[8] is masked
- assert z[9] is masked
+ assert_(z.dtype is x.dtype)
+ assert_(z[3] is masked)
+ assert_(z[4] is not masked)
+ assert_(z[7] is not masked)
+ assert_(z[8] is masked)
+ assert_(z[9] is masked)
def test_where_with_masked_condition(self):
x = array([1., 2., 3., 4., 5.])
@@ -3090,9 +3084,9 @@ class TestMaskedArrayFunctions(TestCase):
c[0] = masked
z = where(c, x, -x)
assert_equal(z, [1., 2., 0., -4., -5])
- assert z[0] is masked
- assert z[1] is not masked
- assert z[2] is masked
+ assert_(z[0] is masked)
+ assert_(z[1] is not masked)
+ assert_(z[2] is masked)
#
x = arange(1, 6)
x[-1] = masked
@@ -3103,7 +3097,7 @@ class TestMaskedArrayFunctions(TestCase):
z = where(c, x, y)
zm = where(cm, x, y)
assert_equal(z, zm)
- assert getmask(zm) is nomask
+ assert_(getmask(zm) is nomask)
assert_equal(zm, [1, 2, 3, 40, 50])
z = where(c, masked, 1)
assert_equal(z, [99, 99, 99, 1, 1])