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