From 2681d335119fb3fc9ff00a847065150913af81e0 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 9 Aug 2019 15:12:54 +0200 Subject: [PATCH] Backport PR #15007: FIX: support pandas 0.25 --- lib/matplotlib/cbook/__init__.py | 8 +++++++- lib/matplotlib/tests/test_axes.py | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index dcb2d0549dea..188b56298c17 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -2061,7 +2061,13 @@ def _check_1d(x): return np.atleast_1d(x) else: try: - x[:, None] + ndim = x[:, None].ndim + # work around https://github.com/pandas-dev/pandas/issues/27775 + # which mean the shape is not as expected. That this ever worked + # was an unintentional quirk of pandas the above line will raise + # an exception in the future. + if ndim < 2: + return np.atleast_1d(x) return x except (IndexError, TypeError): return np.atleast_1d(x) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index dde856669089..26c073e58360 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5170,6 +5170,12 @@ def test_pandas_errorbar_indexing(pd): ax.errorbar('x', 'y', xerr='xe', yerr='ye', data=df) +def test_pandas_index_shape(pd): + df = pd.DataFrame({"XX": [4, 5, 6], "YY": [7, 1, 2]}) + fig, ax = plt.subplots() + ax.plot(df.index, df['YY']) + + def test_pandas_indexing_hist(pd): ser_1 = pd.Series(data=[1, 2, 2, 3, 3, 4, 4, 4, 4, 5]) ser_2 = ser_1.iloc[1:]