13
13
14
14
15
15
class TestUnitData (object ):
16
- testdata = [("hello world" , [ "hello world" ], [ 0 ] ),
17
- ("Здравствуйте мир" , [ "Здравствуйте мир" ], [ 0 ] ),
16
+ testdata = [("hello world" , { "hello world" : 0 } ),
17
+ ("Здравствуйте мир" , { "Здравствуйте мир" : 0 } ),
18
18
(['A' , 'A' , np .nan , 'B' , - np .inf , 3.14 , np .inf ],
19
- ['A' , 'nan' , 'B' , '-inf' , '3.14' , 'inf' ],
20
- [0 , - 1 , 1 , - 3 , 2 , - 2 ])]
21
-
19
+ {'A' : 0 , 'nan' : 1 , 'B' : 2 , '-inf' : 3 , '3.14' : 4 , 'inf' : 5 })]
22
20
ids = ["single" , "unicode" , "mixed" ]
23
21
24
- @pytest .mark .parametrize ("data, seq, locs" , testdata , ids = ids )
25
- def test_unit (self , data , seq , locs ):
26
- act = cat .UnitData (data )
27
- assert act .seq == seq
28
- assert act .locs == locs
22
+ @pytest .mark .parametrize ("data, mapping" , testdata , ids = ids )
23
+ def test_unit (self , data , mapping ):
24
+ assert cat .UnitData (data )._mapping == mapping
29
25
30
26
def test_update_map (self ):
31
27
unitdata = cat .UnitData (['a' , 'd' ])
32
- assert unitdata .seq == ['a' , 'd' ]
33
- assert unitdata .locs == [0 , 1 ]
28
+ assert unitdata ._mapping == {'a' : 0 , 'd' : 1 }
29
+ unitdata .update (['b' , 'd' , 'e' ])
30
+ assert unitdata ._mapping == {'a' : 0 , 'd' : 1 , 'b' : 2 , 'e' : 3 }
31
+
34
32
35
- unitdata . update ([ 'b' , 'd' , 'e' , np . inf ])
36
- assert unitdata . seq == [ 'a' , 'd' , 'b' , 'e' , 'inf' ]
37
- assert unitdata . locs == [ 0 , 1 , 2 , 3 , - 2 ]
33
+ class MockUnitData :
34
+ def __init__ ( self , mapping ):
35
+ self . _mapping = mapping
38
36
39
37
40
38
class FakeAxis (object ):
41
39
def __init__ (self , unit_data ):
42
40
self .unit_data = unit_data
43
41
44
42
45
- class MockUnitData (object ):
46
- def __init__ (self , data ):
47
- seq , locs = zip (* data )
48
- self .seq = list (seq )
49
- self .locs = list (locs )
50
-
51
-
52
43
class TestStrCategoryConverter (object ):
53
44
"""Based on the pandas conversion and factorization tests:
54
45
55
46
ref: /pandas/tseries/tests/test_converter.py
56
47
/pandas/tests/test_algos.py:TestFactorize
57
48
"""
58
- testdata = [("Здравствуйте мир" , [( "Здравствуйте мир" , 42 )] , 42 ),
59
- ("hello world" , [( "hello world" , 42 )] , 42 ),
49
+ testdata = [("Здравствуйте мир" , { "Здравствуйте мир" : 42 } , 42 ),
50
+ ("hello world" , { "hello world" : 42 } , 42 ),
60
51
(['a' , 'b' , 'b' , 'a' , 'a' , 'c' , 'c' , 'c' ],
61
- [( 'a' , 0 ), ( 'b' , 1 ), ( 'c' , 2 )] ,
52
+ { 'a' : 0 , 'b' : 1 , 'c' : 2 } ,
62
53
[0 , 1 , 1 , 0 , 0 , 2 , 2 , 2 ]),
63
- (['A' , 'A' , np .nan , 'B' , - np .inf , 3.14 , np .inf ],
64
- [('nan' , - 1 ), ('3.14' , 0 ), ('A' , 1 ), ('B' , 2 ),
65
- ('-inf' , 100 ), ('inf' , 200 )],
66
- [1 , 1 , - 1 , 2 , 100 , 0 , 200 ])]
54
+ (['A' , 'A' , 'B' , 3.14 ],
55
+ {'A' : 1 , 'B' : 2 },
56
+ [1 , 1 , 2 , 3.14 ])]
67
57
ids = ["unicode" , "single" , "basic" , "mixed" ]
68
58
69
59
@pytest .fixture (autouse = True )
@@ -78,7 +68,7 @@ def test_convert(self, data, unitmap, exp):
78
68
np .testing .assert_array_equal (act , exp )
79
69
80
70
def test_axisinfo (self ):
81
- MUD = MockUnitData ([( None , None )] )
71
+ MUD = MockUnitData ({ None : None } )
82
72
axis = FakeAxis (MUD )
83
73
ax = self .cc .axisinfo (None , axis )
84
74
assert isinstance (ax .majloc , cat .StrCategoryLocator )
@@ -91,8 +81,8 @@ def test_default_units(self):
91
81
92
82
class TestStrCategoryLocator (object ):
93
83
def test_StrCategoryLocator (self ):
94
- locs = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
95
- ticks = cat .StrCategoryLocator (locs )
84
+ locs = list ( range ( 10 ))
85
+ ticks = cat .StrCategoryLocator ({ str ( x ): x for x in locs } )
96
86
np .testing .assert_array_equal (ticks .tick_values (None , None ), locs )
97
87
98
88
@@ -137,27 +127,18 @@ def data(self):
137
127
self .d = ['a' , 'b' , 'c' , 'a' ]
138
128
self .dticks = [0 , 1 , 2 ]
139
129
self .dlabels = ['a' , 'b' , 'c' ]
140
- unitmap = [( 'a' , 0 ), ( 'b' , 1 ), ( 'c' , 2 )]
130
+ unitmap = { 'a' : 0 , 'b' : 1 , 'c' : 2 }
141
131
self .dunit_data = MockUnitData (unitmap )
142
132
143
- @pytest .fixture
144
- def missing_data (self ):
145
- self .dm = ['here' , np .nan , 'here' , 'there' ]
146
- self .dmticks = [0 , - 1 , 1 ]
147
- self .dmlabels = ['here' , 'nan' , 'there' ]
148
- unitmap = [('here' , 0 ), ('nan' , - 1 ), ('there' , 1 )]
149
- self .dmunit_data = MockUnitData (unitmap )
150
-
151
133
def axis_test (self , axis , ticks , labels , unit_data ):
152
134
np .testing .assert_array_equal (axis .get_majorticklocs (), ticks )
153
135
assert lt (axis .get_majorticklabels ()) == labels
154
- np .testing .assert_array_equal (axis .unit_data .locs , unit_data .locs )
155
- assert axis .unit_data .seq == unit_data .seq
136
+ assert axis .unit_data ._mapping == unit_data ._mapping
156
137
157
138
def test_plot_unicode (self ):
158
139
words = ['Здравствуйте' , 'привет' ]
159
140
locs = [0.0 , 1.0 ]
160
- unit_data = MockUnitData (zip (words , locs ))
141
+ unit_data = MockUnitData (dict ( zip (words , locs ) ))
161
142
162
143
fig , ax = plt .subplots ()
163
144
ax .plot (words )
@@ -173,14 +154,6 @@ def test_plot_1d(self):
173
154
174
155
self .axis_test (ax .yaxis , self .dticks , self .dlabels , self .dunit_data )
175
156
176
- @pytest .mark .usefixtures ("missing_data" )
177
- def test_plot_1d_missing (self ):
178
- fig , ax = plt .subplots ()
179
- ax .plot (self .dm )
180
- fig .canvas .draw ()
181
-
182
- self .axis_test (ax .yaxis , self .dmticks , self .dmlabels , self .dmunit_data )
183
-
184
157
@pytest .mark .usefixtures ("data" )
185
158
@pytest .mark .parametrize ("bars" , bytes_data , ids = bytes_ids )
186
159
def test_plot_bytes (self , bars ):
@@ -200,28 +173,9 @@ def test_plot_numlike(self, bars):
200
173
ax .bar (bars , counts )
201
174
fig .canvas .draw ()
202
175
203
- unitmap = MockUnitData ([( '1' , 0 ), ( '11' , 1 ), ( '3' , 2 )] )
176
+ unitmap = MockUnitData ({ '1' : 0 , '11' : 1 , '3' : 2 } )
204
177
self .axis_test (ax .xaxis , [0 , 1 , 2 ], ['1' , '11' , '3' ], unitmap )
205
178
206
- @pytest .mark .usefixtures ("data" , "missing_data" )
207
- def test_plot_2d (self ):
208
- fig , ax = plt .subplots ()
209
- ax .plot (self .dm , self .d )
210
- fig .canvas .draw ()
211
-
212
- self .axis_test (ax .xaxis , self .dmticks , self .dmlabels , self .dmunit_data )
213
- self .axis_test (ax .yaxis , self .dticks , self .dlabels , self .dunit_data )
214
-
215
- @pytest .mark .usefixtures ("data" , "missing_data" )
216
- def test_scatter_2d (self ):
217
-
218
- fig , ax = plt .subplots ()
219
- ax .scatter (self .dm , self .d )
220
- fig .canvas .draw ()
221
-
222
- self .axis_test (ax .xaxis , self .dmticks , self .dmlabels , self .dmunit_data )
223
- self .axis_test (ax .yaxis , self .dticks , self .dlabels , self .dunit_data )
224
-
225
179
def test_plot_update (self ):
226
180
fig , ax = plt .subplots ()
227
181
@@ -232,6 +186,6 @@ def test_plot_update(self):
232
186
233
187
labels = ['a' , 'b' , 'd' , 'c' ]
234
188
ticks = [0 , 1 , 2 , 3 ]
235
- unit_data = MockUnitData (list (zip (labels , ticks )))
189
+ unit_data = MockUnitData (dict (zip (labels , ticks )))
236
190
237
191
self .axis_test (ax .yaxis , ticks , labels , unit_data )
0 commit comments