|
1 | 1 | import unittest |
| 2 | +from datetime import datetime |
| 3 | + |
2 | 4 | import numpy as np |
3 | 5 | import matplotlib.cbook as cbook |
4 | | - |
5 | | -class TestAxes(unittest.TestCase): |
6 | | - def test_delete_masked_points_arrays(self): |
7 | | - input = ( [1,2,3,np.nan,5], |
8 | | - np.array((1,2,3,4,5)), |
9 | | - ) |
10 | | - expected = [np.array((1,2,3,5))]*2 |
11 | | - actual = cbook.delete_masked_points(*input) |
12 | | - assert np.allclose(actual, expected) |
13 | | - |
14 | | - input = ( np.ma.array( [1,2,3,4,5], mask=[False,False,False,True,False] ), |
15 | | - np.array((1,2,3,4,5)), |
16 | | - ) |
17 | | - expected = [np.array((1,2,3,5))]*2 |
18 | | - actual = cbook.delete_masked_points(*input) |
19 | | - assert np.allclose(actual, expected) |
20 | | - |
21 | | - input = ( [1,2,3,np.nan,5], |
22 | | - np.ma.array( [1,2,3,4,5], mask=[False,False,False,True,False] ), |
23 | | - np.array((1,2,3,4,5)), |
24 | | - ) |
25 | | - expected = [np.array((1,2,3,5))]*3 |
26 | | - actual = cbook.delete_masked_points(*input) |
27 | | - assert np.allclose(actual, expected) |
28 | | - |
29 | | - input = () |
30 | | - expected = () |
31 | | - actual = cbook.delete_masked_points(*input) |
32 | | - assert np.allclose(actual, expected) |
33 | | - |
34 | | - |
35 | | - input = ( [1,2,3,np.nan,5], |
36 | | - ) |
37 | | - expected = [np.array((1,2,3,5))]*1 |
38 | | - actual = cbook.delete_masked_points(*input) |
39 | | - assert np.allclose(actual, expected) |
40 | | - |
41 | | - input = ( np.array((1,2,3,4,5)), |
42 | | - ) |
43 | | - expected = [np.array((1,2,3,4,5))]*1 |
44 | | - actual = cbook.delete_masked_points(*input) |
45 | | - assert np.allclose(actual, expected) |
46 | | - |
47 | | - def test_delete_masked_points_strings(self): |
48 | | - input = ( 'hello', |
49 | | - ) |
50 | | - expected = ('hello',) |
51 | | - actual = cbook.delete_masked_points(*input) |
52 | | - assert actual == expected |
53 | | - |
54 | | - input = ( u'hello', |
55 | | - ) |
56 | | - expected = (u'hello',) |
57 | | - actual = cbook.delete_masked_points(*input) |
58 | | - assert actual == expected |
| 6 | +import matplotlib.colors as mcolors |
| 7 | + |
| 8 | +from matplotlib.cbook import delete_masked_points as dmp |
| 9 | + |
| 10 | +class Test_delete_masked_points(unittest.TestCase): |
| 11 | + def setUp(self): |
| 12 | + self.mask1 = [False, False, True, True, False, False] |
| 13 | + self.arr0 = np.arange(1.0,7.0) |
| 14 | + self.arr1 = [1,2,3,np.nan,np.nan,6] |
| 15 | + self.arr2 = np.array(self.arr1) |
| 16 | + self.arr3 = np.ma.array(self.arr2, mask=self.mask1) |
| 17 | + self.arr_s = ['a', 'b', 'c', 'd', 'e', 'f'] |
| 18 | + self.arr_s2 = np.array(self.arr_s) |
| 19 | + self.arr_dt = [datetime(2008, 1, 1), datetime(2008, 1, 2), |
| 20 | + datetime(2008, 1, 3), datetime(2008, 1, 4), |
| 21 | + datetime(2008, 1, 5), datetime(2008, 1, 6)] |
| 22 | + self.arr_dt2 = np.array(self.arr_dt) |
| 23 | + self.arr_colors = ['r', 'g', 'b', 'c', 'm', 'y'] |
| 24 | + self.arr_rgba = mcolors.colorConverter.to_rgba_array(self.arr_colors) |
| 25 | + |
| 26 | + def test_bad_first_arg(self): |
| 27 | + self.assertRaises(ValueError, dmp, 'a string', self.arr0) |
| 28 | + |
| 29 | + def test_string_seq(self): |
| 30 | + actual = dmp(self.arr_s, self.arr1) |
| 31 | + ind = [0, 1, 2, 5] |
| 32 | + expected = (self.arr_s2.take(ind), self.arr2.take(ind)) |
| 33 | + |
| 34 | + def test_datetime(self): |
| 35 | + actual = dmp(self.arr_dt, self.arr3) |
| 36 | + ind = [0, 1, 5] |
| 37 | + expected = (self.arr_dt2.take(ind), |
| 38 | + self.arr3.take(ind).compressed()) |
| 39 | + self.assert_(np.all(actual[0] == expected[0]) and |
| 40 | + np.all(actual[1] == expected[1])) |
| 41 | + |
| 42 | + def test_rgba(self): |
| 43 | + actual = dmp(self.arr3, self.arr_rgba) |
| 44 | + ind = [0, 1, 5] |
| 45 | + expected = (self.arr3.take(ind).compressed(), |
| 46 | + self.arr_rgba.take(ind, axis=0)) |
| 47 | + self.assert_(np.all(actual[0] == expected[0]) and |
| 48 | + np.all(actual[1] == expected[1])) |
59 | 49 |
|
60 | 50 |
|
61 | 51 | if __name__=='__main__': |
|
0 commit comments