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
- ['-inf' , '3.14' , 'A' , 'B' , 'inf' , 'nan' ],
20
- [- 3.0 , 0 , 1 , 2 , - 2.0 , - 1.0 ])]
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
- data = ['a' , 'd' ]
32
- oseq = ['a' , 'd' ]
33
- olocs = [0 , 1 ]
34
-
35
- data_update = ['b' , 'd' , 'e' , np .inf ]
36
- useq = ['a' , 'd' , 'b' , 'e' , 'inf' ]
37
- ulocs = [0 , 1 , 2 , 3 , - 2 ]
27
+ unitdata = cat .UnitData (['a' , 'd' ])
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 }
38
31
39
- unitdata = cat .UnitData (data )
40
- assert unitdata .seq == oseq
41
- assert unitdata .locs == olocs
42
32
43
- unitdata . update ( data_update )
44
- assert unitdata . seq == useq
45
- assert unitdata . locs == ulocs
33
+ class MockUnitData :
34
+ def __init__ ( self , mapping ):
35
+ self . _mapping = mapping
46
36
47
37
48
38
class FakeAxis (object ):
49
39
def __init__ (self , unit_data ):
50
40
self .unit_data = unit_data
51
41
52
42
53
- class MockUnitData (object ):
54
- def __init__ (self , data ):
55
- seq , locs = zip (* data )
56
- self .seq = list (seq )
57
- self .locs = list (locs )
58
-
59
-
60
43
class TestStrCategoryConverter (object ):
61
44
"""Based on the pandas conversion and factorization tests:
62
45
63
46
ref: /pandas/tseries/tests/test_converter.py
64
47
/pandas/tests/test_algos.py:TestFactorize
65
48
"""
66
- testdata = [("Здравствуйте мир" , [( "Здравствуйте мир" , 42 )] , 42 ),
67
- ("hello world" , [( "hello world" , 42 )] , 42 ),
49
+ testdata = [("Здравствуйте мир" , { "Здравствуйте мир" : 42 } , 42 ),
50
+ ("hello world" , { "hello world" : 42 } , 42 ),
68
51
(['a' , 'b' , 'b' , 'a' , 'a' , 'c' , 'c' , 'c' ],
69
- [( 'a' , 0 ), ( 'b' , 1 ), ( 'c' , 2 )] ,
52
+ { 'a' : 0 , 'b' : 1 , 'c' : 2 } ,
70
53
[0 , 1 , 1 , 0 , 0 , 2 , 2 , 2 ]),
71
- (['A' , 'A' , np .nan , 'B' , - np .inf , 3.14 , np .inf ],
72
- [('nan' , - 1 ), ('3.14' , 0 ), ('A' , 1 ), ('B' , 2 ),
73
- ('-inf' , 100 ), ('inf' , 200 )],
74
- [1 , 1 , - 1 , 2 , 100 , 0 , 200 ])]
54
+ (['A' , 'A' , 'B' , 3.14 ],
55
+ {'3.14' : 0 , 'A' : 1 , 'B' : 2 },
56
+ [1 , 1 , 2 , 0 ])]
75
57
ids = ["unicode" , "single" , "basic" , "mixed" ]
76
58
77
59
@pytest .fixture (autouse = True )
@@ -86,7 +68,7 @@ def test_convert(self, data, unitmap, exp):
86
68
np .testing .assert_array_equal (act , exp )
87
69
88
70
def test_axisinfo (self ):
89
- MUD = MockUnitData ([( None , None )] )
71
+ MUD = MockUnitData ({ None : None } )
90
72
axis = FakeAxis (MUD )
91
73
ax = self .cc .axisinfo (None , axis )
92
74
assert isinstance (ax .majloc , cat .StrCategoryLocator )
@@ -99,8 +81,8 @@ def test_default_units(self):
99
81
100
82
class TestStrCategoryLocator (object ):
101
83
def test_StrCategoryLocator (self ):
102
- locs = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
103
- ticks = cat .StrCategoryLocator (locs )
84
+ locs = list ( range ( 10 ))
85
+ ticks = cat .StrCategoryLocator ({ str ( x ): x for x in locs } )
104
86
np .testing .assert_array_equal (ticks .tick_values (None , None ), locs )
105
87
106
88
@@ -145,27 +127,18 @@ def data(self):
145
127
self .d = ['a' , 'b' , 'c' , 'a' ]
146
128
self .dticks = [0 , 1 , 2 ]
147
129
self .dlabels = ['a' , 'b' , 'c' ]
148
- unitmap = [( 'a' , 0 ), ( 'b' , 1 ), ( 'c' , 2 )]
130
+ unitmap = { 'a' : 0 , 'b' : 1 , 'c' : 2 }
149
131
self .dunit_data = MockUnitData (unitmap )
150
132
151
- @pytest .fixture
152
- def missing_data (self ):
153
- self .dm = ['here' , np .nan , 'here' , 'there' ]
154
- self .dmticks = [0 , - 1 , 1 ]
155
- self .dmlabels = ['here' , 'nan' , 'there' ]
156
- unitmap = [('here' , 0 ), ('nan' , - 1 ), ('there' , 1 )]
157
- self .dmunit_data = MockUnitData (unitmap )
158
-
159
133
def axis_test (self , axis , ticks , labels , unit_data ):
160
134
np .testing .assert_array_equal (axis .get_majorticklocs (), ticks )
161
135
assert lt (axis .get_majorticklabels ()) == labels
162
- np .testing .assert_array_equal (axis .unit_data .locs , unit_data .locs )
163
- assert axis .unit_data .seq == unit_data .seq
136
+ assert axis .unit_data ._mapping == unit_data ._mapping
164
137
165
138
def test_plot_unicode (self ):
166
139
words = ['Здравствуйте' , 'привет' ]
167
140
locs = [0.0 , 1.0 ]
168
- unit_data = MockUnitData (zip (words , locs ))
141
+ unit_data = MockUnitData (dict ( zip (words , locs ) ))
169
142
170
143
fig , ax = plt .subplots ()
171
144
ax .plot (words )
@@ -181,14 +154,6 @@ def test_plot_1d(self):
181
154
182
155
self .axis_test (ax .yaxis , self .dticks , self .dlabels , self .dunit_data )
183
156
184
- @pytest .mark .usefixtures ("missing_data" )
185
- def test_plot_1d_missing (self ):
186
- fig , ax = plt .subplots ()
187
- ax .plot (self .dm )
188
- fig .canvas .draw ()
189
-
190
- self .axis_test (ax .yaxis , self .dmticks , self .dmlabels , self .dmunit_data )
191
-
192
157
@pytest .mark .usefixtures ("data" )
193
158
@pytest .mark .parametrize ("bars" , bytes_data , ids = bytes_ids )
194
159
def test_plot_bytes (self , bars ):
@@ -208,28 +173,9 @@ def test_plot_numlike(self, bars):
208
173
ax .bar (bars , counts )
209
174
fig .canvas .draw ()
210
175
211
- unitmap = MockUnitData ([( '1' , 0 ), ( '11' , 1 ), ( '3' , 2 )] )
176
+ unitmap = MockUnitData ({ '1' : 0 , '11' : 1 , '3' : 2 } )
212
177
self .axis_test (ax .xaxis , [0 , 1 , 2 ], ['1' , '11' , '3' ], unitmap )
213
178
214
- @pytest .mark .usefixtures ("data" , "missing_data" )
215
- def test_plot_2d (self ):
216
- fig , ax = plt .subplots ()
217
- ax .plot (self .dm , self .d )
218
- fig .canvas .draw ()
219
-
220
- self .axis_test (ax .xaxis , self .dmticks , self .dmlabels , self .dmunit_data )
221
- self .axis_test (ax .yaxis , self .dticks , self .dlabels , self .dunit_data )
222
-
223
- @pytest .mark .usefixtures ("data" , "missing_data" )
224
- def test_scatter_2d (self ):
225
-
226
- fig , ax = plt .subplots ()
227
- ax .scatter (self .dm , self .d )
228
- fig .canvas .draw ()
229
-
230
- self .axis_test (ax .xaxis , self .dmticks , self .dmlabels , self .dmunit_data )
231
- self .axis_test (ax .yaxis , self .dticks , self .dlabels , self .dunit_data )
232
-
233
179
def test_plot_update (self ):
234
180
fig , ax = plt .subplots ()
235
181
@@ -240,7 +186,7 @@ def test_plot_update(self):
240
186
241
187
labels = ['a' , 'b' , 'd' , 'c' ]
242
188
ticks = [0 , 1 , 2 , 3 ]
243
- unit_data = MockUnitData (list (zip (labels , ticks )))
189
+ unit_data = MockUnitData (dict (zip (labels , ticks )))
244
190
245
191
self .axis_test (ax .yaxis , ticks , labels , unit_data )
246
192
0 commit comments