@@ -181,20 +181,19 @@ 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
189
190
- for val in vals :
190
+ try :
191
+ float (val )
192
+ except ValueError :
191
193
try :
192
- float (val )
194
+ dateutil . parser . parse (val )
193
195
except ValueError :
194
- try :
195
- dateutil .parser .parse (val )
196
- except ValueError :
197
- return False
196
+ return False
198
197
return True
199
198
200
199
def update (self , data ):
@@ -212,18 +211,23 @@ def update(self, data):
212
211
"""
213
212
data = np .atleast_1d (np .array (data , dtype = object ))
214
213
214
+ # check if convertable to number:
215
+ convertable = True
215
216
for val in OrderedDict .fromkeys (data ):
216
217
# OrderedDict just iterates over unique values in data.
217
218
if not isinstance (val , (str , bytes )):
218
219
raise TypeError ("{val!r} is not a string" .format (val = val ))
220
+ if convertable :
221
+ # this will only be called so long as convertable is True.
222
+ convertable = self ._str_is_convertible (val )
219
223
if val not in self ._mapping :
220
224
self ._mapping [val ] = next (self ._counter )
221
225
# 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.' )
226
+ if convertable :
227
+ _log .info ('Using categrocical units to plot a list of strings '
228
+ 'that are all parsable as floats or dates. If these '
229
+ 'strings should be plotted as numbers , cast to the '
230
+ 'approriate data type before plotting.' )
227
231
228
232
229
233
# Register the converter with Matplotlib's unit framework
0 commit comments