@@ -171,17 +171,20 @@ def __init__(self, data=None):
171
171
self .update (data )
172
172
173
173
@staticmethod
174
- def _str_is_convertable ( val ):
174
+ def _strs_are_convertible ( vals ):
175
175
"""
176
- Helper method to see if string can be cast to float or parsed as date.
176
+ Helper method to see if list of strings can all be cast to float or
177
+ parsed as date.
177
178
"""
178
- try :
179
- float (val )
180
- except ValueError :
179
+
180
+ for val in vals :
181
181
try :
182
- dateutil . parser . parse (val )
182
+ float (val )
183
183
except ValueError :
184
- return False
184
+ try :
185
+ dateutil .parser .parse (val )
186
+ except ValueError :
187
+ return False
185
188
return True
186
189
187
190
def update (self , data ):
@@ -199,16 +202,14 @@ def update(self, data):
199
202
"""
200
203
data = np .atleast_1d (np .array (data , dtype = object ))
201
204
202
- convertable = True
203
205
for val in OrderedDict .fromkeys (data ):
204
206
# OrderedDict just iterates over unique values in data.
205
207
if not isinstance (val , (str , bytes )):
206
208
raise TypeError ("{val!r} is not a string" .format (val = val ))
207
- # check if we can convert string to number or date...
208
- convertable = (convertable and self ._str_is_convertable (val ))
209
209
if val not in self ._mapping :
210
210
self ._mapping [val ] = next (self ._counter )
211
- if convertable :
211
+ # check if we can convert all strings to number or date...
212
+ if self ._strs_are_convertible (data ):
212
213
cbook ._warn_external ('using category units to plot a list of '
213
214
'strings that is a;; floats or parsable as dates. '
214
215
'If you do not mean these to be categories, cast '
0 commit comments