diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 7f7290c6e502..786b8892b8d4 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3926,6 +3926,10 @@ def dopatch(xs, ys, **kwargs): elif len(positions) != N: raise ValueError(datashape_message.format("positions")) + positions = np.array(positions) + if len(positions) > 0 and not isinstance(positions[0], Number): + raise TypeError("positions should be an iterable of numbers") + # width if widths is None: widths = [np.clip(0.15 * np.ptp(positions), 0.15, 0.5)] * N diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 40c23f6c5967..2dbb3c2fba6c 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1524,6 +1524,15 @@ def test_bar_timedelta(): (10, 20)) +def test_boxplot_dates_pandas(pd): + # smoke test for boxplot and dates in pandas + data = np.random.rand(5, 2) + years = pd.date_range('1/1/2000', + periods=2, freq=pd.DateOffset(years=1)).year + plt.figure() + plt.boxplot(data, positions=years) + + def test_bar_pandas(pd): # Smoke test for pandas