From d33d654b2b635aa12ee2deea38ba60920931c43f Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 8 Aug 2019 00:01:41 -0400 Subject: [PATCH 1/3] FIX: support pandas 0.25 closes #14992 --- lib/matplotlib/cbook/__init__.py | 6 +++++- lib/matplotlib/tests/test_axes.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index f0e018c8068e..63602b5418d5 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -1326,7 +1326,11 @@ def _check_1d(x): return np.atleast_1d(x) else: try: - x[:, None] + shape = x[:, None].shape + # work around https://github.com/pandas-dev/pandas/issues/27775 + # which mean the shape is not as expected + if len(shape) != 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 abe33dcf0491..ada6d6ed01c4 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5552,6 +5552,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:] From f30de354ce21b9aeb2952e9c195dca0d1026f1a6 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 8 Aug 2019 00:56:11 -0400 Subject: [PATCH 2/3] STY: fix whitespace --- lib/matplotlib/tests/test_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index ada6d6ed01c4..7daace9a43aa 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5553,7 +5553,7 @@ def test_pandas_errorbar_indexing(pd): def test_pandas_index_shape(pd): - df = pd.DataFrame({"XX" : [4,5,6], "YY" : [7,1,2]}) + df = pd.DataFrame({"XX": [4, 5, 6], "YY": [7, 1, 2]}) fig, ax = plt.subplots() ax.plot(df.index, df['YY']) From df4b7dcb05624fbf9747c4ab2aaf0dce52a67dc5 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 8 Aug 2019 21:02:26 -0400 Subject: [PATCH 3/3] MNT: use a slightly simpler check odd Index behavior This will fail on older version of pandas as well. --- lib/matplotlib/cbook/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index 63602b5418d5..a6a163843a6a 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -1326,10 +1326,12 @@ def _check_1d(x): return np.atleast_1d(x) else: try: - shape = x[:, None].shape + ndim = x[:, None].ndim # work around https://github.com/pandas-dev/pandas/issues/27775 - # which mean the shape is not as expected - if len(shape) != 2: + # 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):