@@ -181,20 +181,19 @@ def __init__(self, data=None):
181181 self .update (data )
182182
183183 @staticmethod
184- def _strs_are_convertible ( vals ):
184+ def _str_is_convertible ( val ):
185185 """
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
187187 parsed as date.
188188 """
189189
190- for val in vals :
190+ try :
191+ float (val )
192+ except ValueError :
191193 try :
192- float (val )
194+ dateutil . parser . parse (val )
193195 except ValueError :
194- try :
195- dateutil .parser .parse (val )
196- except ValueError :
197- return False
196+ return False
198197 return True
199198
200199 def update (self , data ):
@@ -212,18 +211,23 @@ def update(self, data):
212211 """
213212 data = np .atleast_1d (np .array (data , dtype = object ))
214213
214+ # check if convertable to number:
215+ convertable = True
215216 for val in OrderedDict .fromkeys (data ):
216217 # OrderedDict just iterates over unique values in data.
217218 if not isinstance (val , (str , bytes )):
218219 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 )
219223 if val not in self ._mapping :
220224 self ._mapping [val ] = next (self ._counter )
221225 # 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.' )
227231
228232
229233# Register the converter with Matplotlib's unit framework
0 commit comments