From ef9d8b1ef3575b5b984991274cce5fe358a0b5da 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 e2ba3948679d..ed08c5be2ce5 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -1399,7 +1399,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 6e9a276f3947..5cdabee201f7 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5522,6 +5522,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:]