33from __future__ import (absolute_import , division , print_function ,
44 unicode_literals )
55
6+ import six
67import pytest
78import numpy as np
89
10+
911import matplotlib .pyplot as plt
1012import matplotlib .category as cat
1113
12- import unittest
1314
1415
1516class TestUnitData (object ):
16- testdata = [ ("hello world" , ["hello world" ], [0 ]),
17- ("Здравствуйте мир" , ["Здравствуйте мир" ], [0 ]),
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-
22- ids = [ "single" , "unicode" , "mixed" ]
23-
24- @pytest .mark .parametrize ("data, seq, locs" , testdata , ids = ids )
17+ test_cases = { 'single' : ("hello world" , ["hello world" ], [0 ]),
18+ 'unicode' : ("Здравствуйте мир" , ["Здравствуйте мир" ], [0 ]),
19+ 'mixed' : (['A' , 'A' , np .nan , 'B' , - np .inf , 3.14 , np .inf ],
20+ ['-inf' , '3.14' , 'A' , 'B' , 'inf' , 'nan' ],
21+ [- 3.0 , 0 , 1 , 2 , - 2.0 , - 1.0 ])}
22+
23+ ids , data = zip ( * six . iteritems ( test_cases ))
24+
25+ @pytest .mark .parametrize ("data, seq, locs" , data , ids = ids )
2526 def test_unit (self , data , seq , locs ):
2627 act = cat .UnitData (data )
2728 assert act .seq == seq
@@ -63,22 +64,26 @@ class TestStrCategoryConverter(object):
6364 ref: /pandas/tseries/tests/test_converter.py
6465 /pandas/tests/test_algos.py:TestFactorize
6566 """
66- testdata = [("Здравствуйте мир" , [("Здравствуйте мир" , 42 )], 42 ),
67- ("hello world" , [("hello world" , 42 )], 42 ),
68- (['a' , 'b' , 'b' , 'a' , 'a' , 'c' , 'c' , 'c' ],
69- [('a' , 0 ), ('b' , 1 ), ('c' , 2 )],
70- [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 ])]
75- ids = ["unicode" , "single" , "basic" , "mixed" ]
67+
68+ test_cases = {"unicode" : ("Здравствуйте мир" , [("Здравствуйте мир" , 42 )], 42 ),
69+ "ascii" : ("hello world" , [("hello world" , 42 )], 42 ),
70+ "single" : (['a' , 'b' , 'b' , 'a' , 'a' , 'c' , 'c' , 'c' ],
71+ [('a' , 0 ), ('b' , 1 ), ('c' , 2 )],
72+ [0 , 1 , 1 , 0 , 0 , 2 , 2 , 2 ]),
73+ "mixed" : (['A' , 'A' , np .nan , 'B' , - np .inf , 3.14 , np .inf ],
74+ [('nan' , - 1 ), ('3.14' , 0 ), ('A' , 1 ), ('B' , 2 ),
75+ ('-inf' , 100 ), ('inf' , 200 )],
76+ [1 , 1 , - 1 , 2 , 100 , 0 , 200 ]),
77+ "integer string" : (["!" , "0" ], [("!" , 0 ), ("0" , 1 )], [0 , 1 ]),
78+ "number" : (0.0 , [(0.0 , 0.0 )], 0.0 )}
79+
80+ ids , data = zip (* six .iteritems (test_cases ))
7681
7782 @pytest .fixture (autouse = True )
7883 def mock_axis (self , request ):
7984 self .cc = cat .StrCategoryConverter ()
8085
81- @pytest .mark .parametrize ("data, unitmap, exp" , testdata , ids = ids )
86+ @pytest .mark .parametrize ("data, unitmap, exp" , data , ids = ids )
8287 def test_convert (self , data , unitmap , exp ):
8388 MUD = MockUnitData (unitmap )
8489 axis = FakeAxis (MUD )
@@ -104,7 +109,7 @@ def test_StrCategoryLocator(self):
104109 np .testing .assert_array_equal (ticks .tick_values (None , None ), locs )
105110
106111
107- class TestStrCategoryFormatter (unittest . TestCase ):
112+ class TestStrCategoryFormatter (object ):
108113 def test_StrCategoryFormatter (self ):
109114 seq = ["hello" , "world" , "hi" ]
110115 labels = cat .StrCategoryFormatter (seq )
@@ -121,24 +126,18 @@ def lt(tl):
121126
122127
123128class TestPlot (object ):
124- bytes_data = [
125- ['a' , 'b' , 'c' ],
126- [b'a' , b'b' , b'c' ],
127- np .array ([b'a' , b'b' , b'c' ])
128- ]
129-
130- bytes_ids = ['string list' , 'bytes list' , 'bytes ndarray' ]
131-
132- numlike_data = [
133- ['1' , '11' , '3' ],
134- np .array (['1' , '11' , '3' ]),
135- [b'1' , b'11' , b'3' ],
136- np .array ([b'1' , b'11' , b'3' ]),
137- ]
138-
139- numlike_ids = [
140- 'string list' , 'string ndarray' , 'bytes list' , 'bytes ndarray'
141- ]
129+ bytes_cases = {'string list' : ['a' , 'b' , 'c' ],
130+ 'bytes list' : [b'a' , b'b' , b'c' ],
131+ 'bytes ndarray' : np .array ([b'a' , b'b' , b'c' ])}
132+
133+ bytes_ids , bytes_data = zip (* six .iteritems (bytes_cases ))
134+
135+ numlike_cases = {'string list' : ['1' , '11' , '3' ],
136+ 'string ndarray' : np .array (['1' , '11' , '3' ]),
137+ 'bytes list' : [b'1' , b'11' , b'3' ],
138+ 'bytes ndarray' : np .array ([b'1' , b'11' , b'3' ])}
139+
140+ numlike_ids , numlike_data = zip (* six .iteritems (numlike_cases ))
142141
143142 @pytest .fixture
144143 def data (self ):
0 commit comments