@@ -181,20 +181,18 @@ def __init__(self, data=None):
181
181
self .update (data )
182
182
183
183
@staticmethod
184
- def _strs_are_convertible ( vals ):
184
+ def _str_is_convertible ( val ):
185
185
"""
186
- Helper method to see if list of strings can all be cast to float or
186
+ Helper method to see if a string can be cast to float or
187
187
parsed as date.
188
188
"""
189
-
190
- for val in vals :
189
+ try :
190
+ float (val )
191
+ except ValueError :
191
192
try :
192
- float (val )
193
+ dateutil . parser . parse (val )
193
194
except ValueError :
194
- try :
195
- dateutil .parser .parse (val )
196
- except ValueError :
197
- return False
195
+ return False
198
196
return True
199
197
200
198
def update (self , data ):
@@ -212,18 +210,22 @@ def update(self, data):
212
210
"""
213
211
data = np .atleast_1d (np .array (data , dtype = object ))
214
212
213
+ # check if convertable to number:
214
+ convertable = True
215
215
for val in OrderedDict .fromkeys (data ):
216
216
# OrderedDict just iterates over unique values in data.
217
217
if not isinstance (val , (str , bytes )):
218
218
raise TypeError ("{val!r} is not a string" .format (val = val ))
219
+ if convertable :
220
+ # this will only be called so long as convertable is True.
221
+ convertable = self ._str_is_convertible (val )
219
222
if val not in self ._mapping :
220
223
self ._mapping [val ] = next (self ._counter )
221
- # check if we can convert all strings to number or date...
222
- if self ._strs_are_convertible (data ):
223
- _log .info ('using category units to plot a list of '
224
- 'strings that is a;; floats or parsable as dates. '
225
- 'If you do not mean these to be categories, cast '
226
- 'to the approriate data type before plotting.' )
224
+ if convertable :
225
+ _log .info ('Using categrocical units to plot a list of strings '
226
+ 'that are all parsable as floats or dates. If these '
227
+ 'strings should be plotted as numbers, cast to the '
228
+ 'approriate data type before plotting.' )
227
229
228
230
229
231
# Register the converter with Matplotlib's unit framework
0 commit comments