diff options
author | pierregm <pierregm@localhost> | 2009-12-18 04:49:20 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2009-12-18 04:49:20 +0000 |
commit | bc2232b84d2c5e50826f715507fa23d70c6c8718 (patch) | |
tree | f5664750757160e8cc65587a905837a4f9d20f66 /numpy/ma/tests | |
parent | f6f1c821fb5bbe83da52e917ccfd66adfd13dc92 (diff) | |
download | numpy-bc2232b84d2c5e50826f715507fa23d70c6c8718.tar.gz |
* Add support for `fill_value` to mvoid
* Simplify mvoid._get_data
* Simplify MaskedArray.tolist and add support for individually masked fields (bug #1330)
Diffstat (limited to 'numpy/ma/tests')
-rw-r--r-- | numpy/ma/tests/test_core.py | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 1549ef3c9..fea0ac0d4 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -482,7 +482,8 @@ class TestMaskedArray(TestCase): def test_filled_w_flexible_dtype(self): "Test filled w/ flexible dtype" - flexi = array([(1, 1, 1)], dtype=[('i', int), ('s', '|S8'), ('f', float)]) + flexi = array([(1, 1, 1)], + dtype=[('i', int), ('s', '|S8'), ('f', float)]) flexi[0] = masked assert_equal(flexi.filled(), np.array([(default_fill_value(0), @@ -492,6 +493,20 @@ class TestMaskedArray(TestCase): assert_equal(flexi.filled(1), np.array([(1, '1', 1.)], dtype=flexi.dtype)) + def test_filled_w_mvoid(self): + "Test filled w/ mvoid" + ndtype = [('a', int), ('b', float)] + a = mvoid(np.array((1, 2)), mask=[(0, 1)], dtype=ndtype) + # Filled using default + test = a.filled() + assert_equal(tuple(test), (1, default_fill_value(1.))) + # Explicit fill_value + test = a.filled((-1, -1)) + assert_equal(tuple(test), (1, -1)) + # Using predefined filling values + a.fill_value = (-999, -999) + assert_equal(tuple(a.filled()), (1, -999)) + def test_filled_w_nested_dtype(self): "Test filled w/ nested dtype" @@ -2290,25 +2305,33 @@ class TestMaskedArrayMethods(TestCase): def test_tolist(self): "Tests to list" + # ... on 1D x = array(np.arange(12)) x[[1, -2]] = masked xlist = x.tolist() self.failUnless(xlist[1] is None) self.failUnless(xlist[-2] is None) - # + # ... on 2D x.shape = (3, 4) xlist = x.tolist() - # + ctrl = [[0, None, 2, 3], [4, 5, 6, 7], [8, 9, None, 11]] assert_equal(xlist[0], [0, None, 2, 3]) assert_equal(xlist[1], [4, 5, 6, 7]) assert_equal(xlist[2], [8, 9, None, 11]) - # Make sure a masked record is output as a tuple of None + assert_equal(xlist, ctrl) + # ... on structured array w/ masked records x = array(zip([1, 2, 3], [1.1, 2.2, 3.3], ['one', 'two', 'thr']), dtype=[('a', int), ('b', float), ('c', '|S8')]) x[-1] = masked - assert_equal(x.tolist(), [(1, 1.1, 'one'), (2, 2.2, 'two'), (None, None, None)]) + assert_equal(x.tolist(), + [(1, 1.1, 'one'), (2, 2.2, 'two'), (None, None, None)]) + # ... on structured array w/ masked fields + a = array([(1, 2,), (3, 4)], mask=[(0, 1), (0, 0)], + dtype=[('a', int), ('b', int)]) + test = a.tolist() + assert_equal(test, [[1, None], [3, 4]]) def test_toflex(self): |