From 72a7d231a8ab27fc0077807b9c06891d9f821954 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 4 Mar 2020 18:20:04 +0000 Subject: [PATCH 1/7] CI: ax.rowNum and ax.colNum attributes deprecated in Matplotlib 3.2 --- pandas/plotting/_matplotlib/tools.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pandas/plotting/_matplotlib/tools.py b/pandas/plotting/_matplotlib/tools.py index 5743288982da4..4195f718be41e 100644 --- a/pandas/plotting/_matplotlib/tools.py +++ b/pandas/plotting/_matplotlib/tools.py @@ -295,13 +295,19 @@ def _handle_shared_axes(axarr, nplots, naxes, nrows, ncols, sharex, sharey): # so that we can correctly handle 'gaps" layout = np.zeros((nrows + 1, ncols + 1), dtype=np.bool) for ax in axarr: - layout[ax.rowNum, ax.colNum] = ax.get_visible() + layout[ + ax.get_subplotspec().rowspan.start, + ax.get_subplotspec().colspan.start, + ] = ax.get_visible() for ax in axarr: # only the last row of subplots should get x labels -> all # other off layout handles the case that the subplot is # the last in the column, because below is no subplot/gap. - if not layout[ax.rowNum + 1, ax.colNum]: + if not layout[ + ax.get_subplotspec().rowspan.start + 1, + ax.ax.get_subplotspec().colspan.start, + ]: continue if sharex or len(ax.get_shared_x_axes().get_siblings(ax)) > 1: _remove_labels_from_axis(ax.xaxis) From 7b58996cd4a2df4553fdd1cc812794f79f59c3f6 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 4 Mar 2020 18:21:45 +0000 Subject: [PATCH 2/7] fix --- pandas/plotting/_matplotlib/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/plotting/_matplotlib/tools.py b/pandas/plotting/_matplotlib/tools.py index 4195f718be41e..1951f7dea2de8 100644 --- a/pandas/plotting/_matplotlib/tools.py +++ b/pandas/plotting/_matplotlib/tools.py @@ -306,7 +306,7 @@ def _handle_shared_axes(axarr, nplots, naxes, nrows, ncols, sharex, sharey): # the last in the column, because below is no subplot/gap. if not layout[ ax.get_subplotspec().rowspan.start + 1, - ax.ax.get_subplotspec().colspan.start, + ax.get_subplotspec().colspan.start, ]: continue if sharex or len(ax.get_shared_x_axes().get_siblings(ax)) > 1: From a569dd7013d69ed8c94f50f09ad05109b87df509 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 4 Mar 2020 18:54:29 +0000 Subject: [PATCH 3/7] fix up older versions --- pandas/plotting/_matplotlib/compat.py | 1 + pandas/plotting/_matplotlib/tools.py | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pandas/plotting/_matplotlib/compat.py b/pandas/plotting/_matplotlib/compat.py index e7855068334f7..f2c5032112bc9 100644 --- a/pandas/plotting/_matplotlib/compat.py +++ b/pandas/plotting/_matplotlib/compat.py @@ -20,3 +20,4 @@ def inner(): _mpl_ge_2_2_3 = _mpl_version("2.2.3", operator.ge) _mpl_ge_3_0_0 = _mpl_version("3.0.0", operator.ge) _mpl_ge_3_1_0 = _mpl_version("3.1.0", operator.ge) +_mpl_ge_3_2_0 = _mpl_version("3.2.0", operator.ge) diff --git a/pandas/plotting/_matplotlib/tools.py b/pandas/plotting/_matplotlib/tools.py index 1951f7dea2de8..c78483086ad0e 100644 --- a/pandas/plotting/_matplotlib/tools.py +++ b/pandas/plotting/_matplotlib/tools.py @@ -9,6 +9,8 @@ from pandas.core.dtypes.common import is_list_like from pandas.core.dtypes.generic import ABCDataFrame, ABCIndexClass, ABCSeries +from pandas.plotting._matplotlib import compat + def format_date_labels(ax, rot): # mini version of autofmt_xdate @@ -288,6 +290,12 @@ def _remove_labels_from_axis(axis): def _handle_shared_axes(axarr, nplots, naxes, nrows, ncols, sharex, sharey): if nplots > 1: + if compat._mpl_ge_3_2_0(): + row_num = lambda x: x.get_subplotspec().rowspan.start + col_num = lambda x: x.get_subplotspec().rowspan.start + else: + row_num = lambda x: x.rowNum + col_num = lambda x: x.colNum if nrows > 1: try: @@ -295,19 +303,13 @@ def _handle_shared_axes(axarr, nplots, naxes, nrows, ncols, sharex, sharey): # so that we can correctly handle 'gaps" layout = np.zeros((nrows + 1, ncols + 1), dtype=np.bool) for ax in axarr: - layout[ - ax.get_subplotspec().rowspan.start, - ax.get_subplotspec().colspan.start, - ] = ax.get_visible() + layout[row_num(ax), col_num(ax)] = ax.get_visible() for ax in axarr: # only the last row of subplots should get x labels -> all # other off layout handles the case that the subplot is # the last in the column, because below is no subplot/gap. - if not layout[ - ax.get_subplotspec().rowspan.start + 1, - ax.get_subplotspec().colspan.start, - ]: + if not layout[row_num(ax) + 1, col_num(ax)]: continue if sharex or len(ax.get_shared_x_axes().get_siblings(ax)) > 1: _remove_labels_from_axis(ax.xaxis) From 4af9394beb8a4d3107d5d7daf5901983a0597381 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 4 Mar 2020 19:53:02 +0000 Subject: [PATCH 4/7] skip tests --- pandas/tests/plotting/test_frame.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index ffbd135466709..3aff66da9f0f8 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -23,6 +23,7 @@ from pandas.io.formats.printing import pprint_thing import pandas.plotting as plotting +from pandas.plotting._matplotlib import compat @td.skip_if_no_mpl @@ -439,6 +440,9 @@ def test_groupby_boxplot_sharey(self): expected = [True, True, True, True] self._assert_ytickslabels_visibility(axes, expected) + @pytest.mark.skipif( + compat._mpl_ge_3_2_0(), reason="https://github.com/pandas-dev/pandas/pull/32444" + ) def test_groupby_boxplot_sharex(self): # https://github.com/pandas-dev/pandas/issues/20968 # sharex can now be switched check whether the right @@ -742,6 +746,9 @@ def test_subplots_ts_share_axes(self): for ax in axes[[0, 1, 2], [2]].ravel(): self._check_visible(ax.get_yticklabels(), visible=False) + @pytest.mark.skipif( + compat._mpl_ge_3_2_0(), reason="https://github.com/pandas-dev/pandas/pull/32444" + ) def test_subplots_sharex_axes_existing_axes(self): # GH 9158 d = {"A": [1.0, 2.0, 3.0, 4.0], "B": [4.0, 3.0, 2.0, 1.0], "C": [5, 1, 3, 4]} From c5095b37d3e494da8793b8f2ca540ae3f31cadb1 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 4 Mar 2020 20:17:12 +0000 Subject: [PATCH 5/7] fixup for Linux py37_np_dev --- pandas/tests/plotting/test_frame.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 3aff66da9f0f8..080913aadcc71 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -440,14 +440,14 @@ def test_groupby_boxplot_sharey(self): expected = [True, True, True, True] self._assert_ytickslabels_visibility(axes, expected) - @pytest.mark.skipif( - compat._mpl_ge_3_2_0(), reason="https://github.com/pandas-dev/pandas/pull/32444" - ) def test_groupby_boxplot_sharex(self): # https://github.com/pandas-dev/pandas/issues/20968 # sharex can now be switched check whether the right # pair of axes is turned on or off + if compat._mpl_ge_3_2_0(): + pytest.skip("https://github.com/pandas-dev/pandas/pull/32444") + df = DataFrame( { "a": [-1.43, -0.15, -3.70, -1.43, -0.14], @@ -746,11 +746,12 @@ def test_subplots_ts_share_axes(self): for ax in axes[[0, 1, 2], [2]].ravel(): self._check_visible(ax.get_yticklabels(), visible=False) - @pytest.mark.skipif( - compat._mpl_ge_3_2_0(), reason="https://github.com/pandas-dev/pandas/pull/32444" - ) def test_subplots_sharex_axes_existing_axes(self): # GH 9158 + + if compat._mpl_ge_3_2_0(): + pytest.skip("https://github.com/pandas-dev/pandas/pull/32444") + d = {"A": [1.0, 2.0, 3.0, 4.0], "B": [4.0, 3.0, 2.0, 1.0], "C": [5, 1, 3, 4]} df = DataFrame(d, index=date_range("2014 10 11", "2014 10 14")) From 3a52a1b378d399b1bb618ed8b322bdc30645206c Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 4 Mar 2020 20:19:57 +0000 Subject: [PATCH 6/7] use self instead of import --- pandas/tests/plotting/test_frame.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 080913aadcc71..62e9d0b837933 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -23,7 +23,6 @@ from pandas.io.formats.printing import pprint_thing import pandas.plotting as plotting -from pandas.plotting._matplotlib import compat @td.skip_if_no_mpl @@ -445,7 +444,7 @@ def test_groupby_boxplot_sharex(self): # sharex can now be switched check whether the right # pair of axes is turned on or off - if compat._mpl_ge_3_2_0(): + if self.mpl_ge_3_2_0: pytest.skip("https://github.com/pandas-dev/pandas/pull/32444") df = DataFrame( @@ -749,7 +748,7 @@ def test_subplots_ts_share_axes(self): def test_subplots_sharex_axes_existing_axes(self): # GH 9158 - if compat._mpl_ge_3_2_0(): + if self.mpl_ge_3_2_0: pytest.skip("https://github.com/pandas-dev/pandas/pull/32444") d = {"A": [1.0, 2.0, 3.0, 4.0], "B": [4.0, 3.0, 2.0, 1.0], "C": [5, 1, 3, 4]} From f5f63825c562b2004fa4ca1edad7ba03c04acf4c Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 5 Mar 2020 09:36:51 +0000 Subject: [PATCH 7/7] fix typo --- pandas/plotting/_matplotlib/tools.py | 2 +- pandas/tests/plotting/test_frame.py | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/pandas/plotting/_matplotlib/tools.py b/pandas/plotting/_matplotlib/tools.py index c78483086ad0e..08d945f679810 100644 --- a/pandas/plotting/_matplotlib/tools.py +++ b/pandas/plotting/_matplotlib/tools.py @@ -292,7 +292,7 @@ def _handle_shared_axes(axarr, nplots, naxes, nrows, ncols, sharex, sharey): if nplots > 1: if compat._mpl_ge_3_2_0(): row_num = lambda x: x.get_subplotspec().rowspan.start - col_num = lambda x: x.get_subplotspec().rowspan.start + col_num = lambda x: x.get_subplotspec().colspan.start else: row_num = lambda x: x.rowNum col_num = lambda x: x.colNum diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 62e9d0b837933..ffbd135466709 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -444,9 +444,6 @@ def test_groupby_boxplot_sharex(self): # sharex can now be switched check whether the right # pair of axes is turned on or off - if self.mpl_ge_3_2_0: - pytest.skip("https://github.com/pandas-dev/pandas/pull/32444") - df = DataFrame( { "a": [-1.43, -0.15, -3.70, -1.43, -0.14], @@ -747,10 +744,6 @@ def test_subplots_ts_share_axes(self): def test_subplots_sharex_axes_existing_axes(self): # GH 9158 - - if self.mpl_ge_3_2_0: - pytest.skip("https://github.com/pandas-dev/pandas/pull/32444") - d = {"A": [1.0, 2.0, 3.0, 4.0], "B": [4.0, 3.0, 2.0, 1.0], "C": [5, 1, 3, 4]} df = DataFrame(d, index=date_range("2014 10 11", "2014 10 14"))