Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6bad665

Browse files
committed
FIX
1 parent 5797522 commit 6bad665

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

lib/matplotlib/category.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,20 @@ def __init__(self, data=None):
177177
self.update(data)
178178

179179
@staticmethod
180-
def _str_is_convertable(val):
180+
def _strs_are_convertible(vals):
181181
"""
182-
Helper method to see if string can be cast to float or parsed as date.
182+
Helper method to see if list of strings can all be cast to float or
183+
parsed as date.
183184
"""
184-
try:
185-
float(val)
186-
except ValueError:
185+
186+
for val in vals:
187187
try:
188-
dateutil.parser.parse(val)
188+
float(val)
189189
except ValueError:
190-
return False
190+
try:
191+
dateutil.parser.parse(val)
192+
except ValueError:
193+
return False
191194
return True
192195

193196
def update(self, data):
@@ -205,16 +208,14 @@ def update(self, data):
205208
"""
206209
data = np.atleast_1d(np.array(data, dtype=object))
207210

208-
convertable = True
209211
for val in OrderedDict.fromkeys(data):
210212
# OrderedDict just iterates over unique values in data.
211213
if not isinstance(val, (str, bytes)):
212214
raise TypeError("{val!r} is not a string".format(val=val))
213-
# check if we can convert string to number or date...
214-
convertable = (convertable and self._str_is_convertable(val))
215215
if val not in self._mapping:
216216
self._mapping[val] = next(self._counter)
217-
if convertable:
217+
# check if we can convert all strings to number or date...
218+
if self._strs_are_convertible(data):
218219
cbook._warn_external('using category units to plot a list of '
219220
'strings that is a;; floats or parsable as dates. '
220221
'If you do not mean these to be categories, cast '

0 commit comments

Comments
 (0)