4
4
"""
5
5
from __future__ import (absolute_import , division , print_function ,
6
6
unicode_literals )
7
-
8
7
import six
9
8
10
9
import numpy as np
11
10
12
- import matplotlib .cbook as cbook
13
11
import matplotlib .units as units
14
12
import matplotlib .ticker as ticker
15
13
14
+ # np 1.6/1.7 support
15
+ from distutils .version import LooseVersion
16
+ import collections
17
+
18
+
19
+ def shim_array (data ):
20
+ if LooseVersion (np .__version__ ) <= LooseVersion ('1.8.0' ):
21
+ if (isinstance (data , six .string_types ) or
22
+ not isinstance (data , collections .Iterable )):
23
+ data = [data ]
24
+ try :
25
+ data = [str (d ) for d in data ]
26
+ except UnicodeEncodeError :
27
+ # this yields gibberish but unicode text doesn't
28
+ # render under numpy1.6 anyway
29
+ data = [d .encode ('utf-8' , 'ignore' ).decode ('utf-8' )
30
+ for d in data ]
31
+
32
+ return np .array (data , dtype = np .unicode )
33
+
16
34
17
35
class StrCategoryConverter (units .ConversionInterface ):
18
36
@staticmethod
@@ -25,7 +43,8 @@ def convert(value, unit, axis):
25
43
if isinstance (value , six .string_types ):
26
44
return vmap [value ]
27
45
28
- vals = np .array (value , dtype = np .unicode )
46
+ vals = shim_array (value )
47
+
29
48
for lab , loc in vmap .items ():
30
49
vals [vals == lab ] = loc
31
50
@@ -81,8 +100,7 @@ def update(self, new_data):
81
100
self ._set_seq_locs (new_data , value )
82
101
83
102
def _set_seq_locs (self , data , value ):
84
- strdata = np .array (data , dtype = np .unicode )
85
- # np.unique makes dateframes work
103
+ strdata = shim_array (data )
86
104
new_s = [d for d in np .unique (strdata ) if d not in self .seq ]
87
105
for ns in new_s :
88
106
self .seq .append (ns )
0 commit comments