44"""
55from __future__ import (absolute_import , division , print_function ,
66 unicode_literals )
7-
87import six
98
109import numpy as np
1110
12- import matplotlib .cbook as cbook
1311import matplotlib .units as units
1412import matplotlib .ticker as ticker
1513
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+
1634
1735class StrCategoryConverter (units .ConversionInterface ):
1836 @staticmethod
@@ -25,7 +43,8 @@ def convert(value, unit, axis):
2543 if isinstance (value , six .string_types ):
2644 return vmap [value ]
2745
28- vals = np .array (value , dtype = np .unicode )
46+ vals = shim_array (value )
47+
2948 for lab , loc in vmap .items ():
3049 vals [vals == lab ] = loc
3150
@@ -81,8 +100,7 @@ def update(self, new_data):
81100 self ._set_seq_locs (new_data , value )
82101
83102 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 )
86104 new_s = [d for d in np .unique (strdata ) if d not in self .seq ]
87105 for ns in new_s :
88106 self .seq .append (ns )
0 commit comments