1414import matplotlib .ticker as ticker
1515
1616
17- # pure hack for numpy 1.6 support
18- from distutils .version import LooseVersion
19-
20- NP_NEW = (LooseVersion (np .version .version ) >= LooseVersion ('1.7' ))
21-
22-
23- def to_array (data , maxlen = 100 ):
24- if NP_NEW :
25- return np .array (data , dtype = np .unicode )
26- if cbook .is_scalar_or_string (data ):
27- data = [data ]
28- try :
29- vals = np .array (data , dtype = ('|S' , maxlen ))
30- except UnicodeEncodeError :
31- # this yields gibberish
32- vals = np .array ([convert_to_string (d ) for d in data ])
33- return vals
34-
35-
3617class StrCategoryConverter (units .ConversionInterface ):
3718 @staticmethod
3819 def convert (value , unit , axis ):
@@ -44,7 +25,7 @@ def convert(value, unit, axis):
4425 if isinstance (value , six .string_types ):
4526 return vmap [value ]
4627
47- vals = to_array (value )
28+ vals = np . array (value , dtype = np . unicode )
4829 for lab , loc in vmap .items ():
4930 vals [vals == lab ] = loc
5031
@@ -79,25 +60,6 @@ def __init__(self, seq):
7960 self .offset_string = ''
8061
8162
82- def convert_to_string (value ):
83- """Helper function for numpy 1.6, can be replaced with
84- np.array(...,dtype=unicode) for all later versions of numpy"""
85-
86- if isinstance (value , six .string_types ):
87- pass
88- elif np .isfinite (value ):
89- value = np .asarray (value , dtype = str )[np .newaxis ][0 ]
90- elif np .isnan (value ):
91- value = 'nan'
92- elif np .isposinf (value ):
93- value = 'inf'
94- elif np .isneginf (value ):
95- value = '-inf'
96- else :
97- raise ValueError ("Unconvertable {}" .format (value ))
98- return value
99-
100-
10163class UnitData (object ):
10264 # debatable makes sense to special code missing values
10365 spdict = {'nan' : - 1.0 , 'inf' : - 2.0 , '-inf' : - 3.0 }
@@ -119,12 +81,11 @@ def update(self, new_data):
11981 self ._set_seq_locs (new_data , value )
12082
12183 def _set_seq_locs (self , data , value ):
122- # magic to make it work under np1.6
123- strdata = to_array (data )
84+ strdata = np .array (data , dtype = np .unicode )
12485 # np.unique makes dateframes work
12586 new_s = [d for d in np .unique (strdata ) if d not in self .seq ]
12687 for ns in new_s :
127- self .seq .append (convert_to_string ( ns ) )
88+ self .seq .append (ns )
12889 if ns in UnitData .spdict .keys ():
12990 self .locs .append (UnitData .spdict [ns ])
13091 else :
0 commit comments