8000 FIX: one-loop version of categorical logging call · matplotlib/matplotlib@0ec990a · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ec990a

Browse files
committed
FIX: one-loop version of categorical logging call
1 parent 2051814 commit 0ec990a

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

lib/matplotlib/category.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,19 @@ def __init__(self, data=None):
175175
self.update(data)
176176

177177
@staticmethod
178-
def _strs_are_convertible(vals):
178+
def _str_is_convertible(val):
179179
"""
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
181181
parsed as date.
182182
"""
183183

184-
for val in vals:
184+
try:
185+
float(val)
186+
except ValueError:
185187
try:
186-
float(val)
188+
dateutil.parser.parse(val)
187189
except ValueError:
188-
try:
189-
dateutil.parser.parse(val)
190-
except ValueError:
191-
return False
190+
return False
192191
return True
193192

194193
def update(self, data):
@@ -206,18 +205,23 @@ def update(self, data):
206205
"""
207206
data = np.atleast_1d(np.array(data, dtype=object))
208207

208+
# check if convertable to number:
209+
convertable = True
209210
for val in OrderedDict.fromkeys(data):
210211
# OrderedDict just iterates over unique values in data.
211212
if not isinstance(val, (str, bytes)):
212213
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)
213217
if val not in self._mapping:
214218
self._mapping[val] = next(self._counter)
215219
# 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.')
221225

222226

223227
# Connects the convertor to matplotlib

0 commit comments

Comments
 (0)
0