Closed
Description
Bug report
Bug summary
Since 2.8.1, parser.parse
in dateutil raises a TypeError instead of ValueError, which is not currently catched in matplotlib.
Code for reproduction
import matplotlib.pyplot as plt
plt.plot(['0-100', '1-2'], [1, 2])
Actual outcome
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~/anaconda3/envs/pylandstats/lib/python3.6/site-packages/matplotlib/category.py in _str_is_convertible(val)
189 try:
--> 190 float(val)
191 except ValueError:
ValueError: could not convert string to float: '0-100'
During handling of the above exception, another exception occurred:
IllegalMonthError Traceback (most recent call last)
~/anaconda3/envs/pylandstats/lib/python3.6/site-packages/dateutil/parser/_parser.py in parse(self, timestr, default, ignoretz, tzinfos, **kwargs)
654 try:
--> 655 ret = self._build_naive(res, default)
656 except ValueError as e:
~/anaconda3/envs/pylandstats/lib/python3.6/site-packages/dateutil/parser/_parser.py in _build_naive(self, res, default)
1237
-> 1238 if cday > monthrange(cyear, cmonth)[1]:
1239 repl['day'] = monthrange(cyear, cmonth)[1]
~/anaconda3/envs/pylandstats/lib/python3.6/calendar.py in monthrange(year, month)
122 if not 1 <= month <= 12:
--> 123 raise IllegalMonthError(month)
124 day1 = weekday(year, month, 1)
IllegalMonthError: bad month number 0; must be 1-12
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-48-a2d8ffb40533> in <module>
----> 1 plt.plot(['0-100', '1-2'], [1, 2])
~/anaconda3/envs/pylandstats/lib/python3.6/site-packages/matplotlib/pyplot.py in plot(scalex, scaley, data, *args, **kwargs)
2793 return gca().plot(
2794 *args, scalex=scalex, scaley=scaley, **({"data": data} if data
-> 2795 is not None else {}), **kwargs)
2796
2797
~/anaconda3/envs/pylandstats/lib/python3.6/site-packages/matplotlib/axes/_axes.py in plot(self, scalex, scaley, data, *args, **kwargs)
1664 """
1665 kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D._alias_map)
-> 1666 lines = [*self._get_lines(*args, data=data, **kwargs)]
1667 for line in lines:
1668 self.add_line(line)
~/anaconda3/envs/pylandstats/lib/python3.6/site-packages/matplotlib/axes/_base.py in __call__(self, *args, **kwargs)
223 this += args[0],
224 args = args[1:]
--> 225 yield from self._plot_args(this, kwargs)
226
227 def get_next_color(self):
~/anaconda3/envs/pylandstats/lib/python3.6/site-packages/matplotlib/axes/_base.py in _plot_args(self, tup, kwargs)
389 x, y = index_of(tup[-1])
390
--> 391 x, y = self._xy_from_xy(x, y)
392
393 if self.command == 'plot':
~/anaconda3/envs/pylandstats/lib/python3.6/site-packages/matplotlib/axes/_base.py in _xy_from_xy(self, x, y)
241 def _xy_from_xy(self, x, y):
242 if self.axes.xaxis is not None and self.axes.yaxis is not None:
--> 243 bx = self.axes.xaxis.update_units(x)
244 by = self.axes.yaxis.update_units(y)
245
~/anaconda3/envs/pylandstats/lib/python3.6/site-packages/matplotlib/axis.py in update_units(self, data)
1491 neednew = self.converter != converter
1492 self.converter = converter
-> 1493 default = self.converter.default_units(data, self)
1494 if default is not None and self.units is None:
1495 self.set_units(default)
~/anaconda3/envs/pylandstats/lib/python3.6/site-packages/matplotlib/category.py in default_units(data, axis)
113 # default_units->axis_info->convert
114 if axis.units is None:
--> 115 axis.set_units(UnitData(data))
116 else:
117 axis.units.update(data)
~/anaconda3/envs/pylandstats/lib/python3.6/site-packages/matplotlib/category.py in __init__(self, data)
179 self._counter = itertools.count()
180 if data is not None:
--> 181 self.update(data)
182
183 @staticmethod
~/anaconda3/envs/pylandstats/lib/python3.6/site-packages/matplotlib/category.py in update(self, data)
219 if convertible:
220 # this will only be called so long as convertible is True.
--> 221 convertible = self._str_is_convertible(val)
222 if val not in self._mapping:
223 self._mapping[val] = next(self._counter)
~/anaconda3/envs/pylandstats/lib/python3.6/site-packages/matplotlib/category.py in _str_is_convertible(val)
191 except ValueError:
192 try:
--> 193 dateutil.parser.parse(val)
194 except ValueError:
195 return False
~/anaconda3/envs/pylandstats/lib/python3.6/site-packages/dateutil/parser/_parser.py in parse(timestr, parserinfo, **kwargs)
1372 return parser(parserinfo).parse(timestr, **kwargs)
1373 else:
-> 1374 return DEFAULTPARSER.parse(timestr, **kwargs)
1375
1376
~/anaconda3/envs/pylandstats/lib/python3.6/site-packages/dateutil/parser/_parser.py in parse(self, timestr, default, ignoretz, tzinfos, **kwargs)
655 ret = self._build_naive(res, default)
656 except ValueError as e:
--> 657 six.raise_from(ParserError(e.args[0] + ": %s", timestr), e)
658
659 if not ignoretz:
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Expected outcome
A plot with two string x-ticks '0-100' and '1-2' and two integer y-ticks 1 and 2.
Matplotlib version
- Operating system: Ubuntu 18.04
- Matplotlib version: 3.1.2
- Matplotlib backend (
print(matplotlib.get_backend())
): module://ipykernel.pylab.backend_inline - Python version: 3.6
- Jupyter version (if applicable): 4.6.1
- Other libraries: python-dateutil 2.8.1:
All libraries installed from the conda-forge channel.