11import numpy as np
2+ from numpy .testing .utils import assert_array_equal
23import matplotlib .cbook as cbook
3- from nose .tools import assert_equal
4+ import matplotlib .colors as mcolors
5+ from nose .tools import assert_equal , raises
6+ from datetime import datetime
47
58def test_is_string_like ():
69 y = np .arange ( 10 )
@@ -27,3 +30,50 @@ def test_restrict_dict():
2730 assert_equal (d5 , {'foo' : 'bar' })
2831 # check that d was not modified
2932 assert_equal (d , {'foo' : 'bar' , 1 : 2 })
33+
34+ from matplotlib .cbook import delete_masked_points as dmp
35+
36+ class Test_delete_masked_points ():
37+ def setUp (self ):
38+ self .mask1 = [False , False , True , True , False , False ]
39+ self .arr0 = np .arange (1.0 ,7.0 )
40+ self .arr1 = [1 ,2 ,3 ,np .nan ,np .nan ,6 ]
41+ self .arr2 = np .array (self .arr1 )
42+ self .arr3 = np .ma .array (self .arr2 , mask = self .mask1 )
43+ self .arr_s = ['a' , 'b' , 'c' , 'd' , 'e' , 'f' ]
44+ self .arr_s2 = np .array (self .arr_s )
45+ self .arr_dt = [datetime (2008 , 1 , 1 ), datetime (2008 , 1 , 2 ),
46+ datetime (2008 , 1 , 3 ), datetime (2008 , 1 , 4 ),
47+ datetime (2008 , 1 , 5 ), datetime (2008 , 1 , 6 )]
48+ self .arr_dt2 = np .array (self .arr_dt )
49+ self .arr_colors = ['r' , 'g' , 'b' , 'c' , 'm' , 'y' ]
50+ self .arr_rgba = mcolors .colorConverter .to_rgba_array (self .arr_colors )
51+
52+ @raises (ValueError )
53+ def test_bad_first_arg (self ):
54+ dmp ('a string' , self .arr0 )
55+
56+ def test_string_seq (self ):
57+ actual = dmp (self .arr_s , self .arr1 )
58+ ind = [0 , 1 , 2 , 5 ]
59+ expected = (self .arr_s2 .take (ind ), self .arr2 .take (ind ))
60+ assert_array_equal (actual [0 ], expected [0 ])
61+ assert_array_equal (actual [1 ], expected [1 ])
62+
63+ def test_datetime (self ):
64+ actual = dmp (self .arr_dt , self .arr3 )
65+ ind = [0 , 1 , 5 ]
66+ expected = (self .arr_dt2 .take (ind ),
67+ self .arr3 .take (ind ).compressed ())
68+ assert_array_equal (actual [0 ], expected [0 ])
69+ assert_array_equal (actual [1 ], expected [1 ])
70+
71+ def test_rgba (self ):
72+ actual = dmp (self .arr3 , self .arr_rgba )
73+ ind = [0 , 1 , 5 ]
74+ expected = (self .arr3 .take (ind ).compressed (),
75+ self .arr_rgba .take (ind , axis = 0 ))
76+ assert_array_equal (actual [0 ], expected [0 ])
77+ assert_array_equal (actual [1 ], expected [1 ])
78+
79+
0 commit comments