From 9d5af71a1674c6d9b0cfbb74b445657914b18298 Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 31 Mar 2021 17:57:03 -0700 Subject: [PATCH 1/7] COMPAT: matplotlib 3.4.0 --- pandas/core/groupby/ops.py | 4 +++- pandas/plotting/_matplotlib/compat.py | 1 + pandas/plotting/_matplotlib/tools.py | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index 4c086f3b8612e..88077ec0fed72 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -271,7 +271,7 @@ def apply(self, f: F, data: FrameOrSeries, axis: int = 0): # TODO(ArrayManager) don't use fast_apply / libreduction.apply_frame_axis0 # for now -> relies on BlockManager internals pass - elif ( + elif False and ( com.get_callable_name(f) not in base.plotting_methods and isinstance(splitter, FrameSplitter) and axis == 0 @@ -293,6 +293,7 @@ def apply(self, f: F, data: FrameOrSeries, axis: int = 0): if len(result_values) == len(group_keys): return group_keys, result_values, mutated + # This is where __iter__ is called for key, (i, group) in zip(group_keys, splitter): object.__setattr__(group, "name", key) @@ -307,6 +308,7 @@ def apply(self, f: F, data: FrameOrSeries, axis: int = 0): # fast apply loop was broken prematurely but we have # already the result for the first group which we can reuse. elif i == 0: + assert False continue # group might be modified diff --git a/pandas/plotting/_matplotlib/compat.py b/pandas/plotting/_matplotlib/compat.py index 964596d9b6319..729d2bf1f019a 100644 --- a/pandas/plotting/_matplotlib/compat.py +++ b/pandas/plotting/_matplotlib/compat.py @@ -22,3 +22,4 @@ def inner(): mpl_ge_3_1_0 = _mpl_version("3.1.0", operator.ge) mpl_ge_3_2_0 = _mpl_version("3.2.0", operator.ge) mpl_ge_3_3_0 = _mpl_version("3.3.0", operator.ge) +mpl_ge_3_4_0 = _mpl_version("3.4.0", operator.ge) diff --git a/pandas/plotting/_matplotlib/tools.py b/pandas/plotting/_matplotlib/tools.py index 500d570835493..9e1f54e5e12bc 100644 --- a/pandas/plotting/_matplotlib/tools.py +++ b/pandas/plotting/_matplotlib/tools.py @@ -392,6 +392,11 @@ def handle_shared_axes( row_num = lambda x: x.rowNum col_num = lambda x: x.colNum + if compat.mpl_ge_3_4_0: + is_first_col = lambda x: x.get_subplotspec().is_first_col() + else: + is_first_col = lambda x: x.is_first_col() + if nrows > 1: try: # first find out the ax layout, @@ -423,7 +428,7 @@ def handle_shared_axes( # only the first column should get y labels -> set all other to # off as we only have labels in the first column and we always # have a subplot there, we can skip the layout test - if ax.is_first_col(): + if is_first_col(ax): continue if sharey or _has_externally_shared_axis(ax, "y"): _remove_labels_from_axis(ax.yaxis) From e8022b49d712a631ff152070b0ad9c6bb20bcee6 Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 31 Mar 2021 17:58:03 -0700 Subject: [PATCH 2/7] revert accidental --- pandas/core/groupby/ops.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index 88077ec0fed72..4c086f3b8612e 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -271,7 +271,7 @@ def apply(self, f: F, data: FrameOrSeries, axis: int = 0): # TODO(ArrayManager) don't use fast_apply / libreduction.apply_frame_axis0 # for now -> relies on BlockManager internals pass - elif False and ( + elif ( com.get_callable_name(f) not in base.plotting_methods and isinstance(splitter, FrameSplitter) and axis == 0 @@ -293,7 +293,6 @@ def apply(self, f: F, data: FrameOrSeries, axis: int = 0): if len(result_values) == len(group_keys): return group_keys, result_values, mutated - # This is where __iter__ is called for key, (i, group) in zip(group_keys, splitter): object.__setattr__(group, "name", key) @@ -308,7 +307,6 @@ def apply(self, f: F, data: FrameOrSeries, axis: int = 0): # fast apply loop was broken prematurely but we have # already the result for the first group which we can reuse. elif i == 0: - assert False continue # group might be modified From 2c637923d94fa39bc585d6340773efaa049c1551 Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 31 Mar 2021 18:56:12 -0700 Subject: [PATCH 3/7] fail --- pandas/tests/plotting/frame/test_frame.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index bed60be169e57..40d555be72680 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -32,6 +32,7 @@ from pandas.io.formats.printing import pprint_thing import pandas.plotting as plotting +from pandas.plotting._matplotlib import compat pytestmark = pytest.mark.slow @@ -746,7 +747,7 @@ def test_plot_scatter_with_categorical_data(self, x, y): _check_plot_works(df.plot.scatter, x=x, y=y) - def test_plot_scatter_with_c(self): + def test_plot_scatter_with_c(self, request): df = DataFrame( np.random.randn(6, 4), index=list(string.ascii_letters[:6]), @@ -760,6 +761,10 @@ def test_plot_scatter_with_c(self): # n.b. there appears to be no public method # to get the colorbar label + if compat.mpl_ge_3_4_0: + mark = pytest.mark.xfail(reason="_label attribute removed") + request.node.add_marker(mark) + assert ax.collections[0].colorbar._label == "z" cm = "cubehelix" From 8d9aee8019ac048672630cea5e6ad4415efd4af3 Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 31 Mar 2021 19:42:08 -0700 Subject: [PATCH 4/7] lazify import --- pandas/tests/plotting/frame/test_frame.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index 40d555be72680..53f859cc4a3eb 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -32,7 +32,6 @@ from pandas.io.formats.printing import pprint_thing import pandas.plotting as plotting -from pandas.plotting._matplotlib import compat pytestmark = pytest.mark.slow @@ -748,6 +747,8 @@ def test_plot_scatter_with_categorical_data(self, x, y): _check_plot_works(df.plot.scatter, x=x, y=y) def test_plot_scatter_with_c(self, request): + from pandas.plotting._matplotlib.compat import mpl_ge_3_4_0 + df = DataFrame( np.random.randn(6, 4), index=list(string.ascii_letters[:6]), @@ -761,7 +762,7 @@ def test_plot_scatter_with_c(self, request): # n.b. there appears to be no public method # to get the colorbar label - if compat.mpl_ge_3_4_0: + if mpl_ge_3_4_0: mark = pytest.mark.xfail(reason="_label attribute removed") request.node.add_marker(mark) From e1b2c3be9b6a5fe5b808a41f80f1739cecfc2dca Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 1 Apr 2021 09:44:40 -0700 Subject: [PATCH 5/7] mpl_ge_3_4_0 is callable --- pandas/tests/plotting/frame/test_frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index 53f859cc4a3eb..37cd7e4a2641d 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -762,7 +762,7 @@ def test_plot_scatter_with_c(self, request): # n.b. there appears to be no public method # to get the colorbar label - if mpl_ge_3_4_0: + if mpl_ge_3_4_0(): mark = pytest.mark.xfail(reason="_label attribute removed") request.node.add_marker(mark) From 58bbfc20c80ff97d825b69fa2ae9fda6e3e4d2d7 Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 1 Apr 2021 10:29:27 -0700 Subject: [PATCH 6/7] fixup mpl_ge_3_4_0 is callable --- 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 9e1f54e5e12bc..03d73d1d36953 100644 --- a/pandas/plotting/_matplotlib/tools.py +++ b/pandas/plotting/_matplotlib/tools.py @@ -392,7 +392,7 @@ def handle_shared_axes( row_num = lambda x: x.rowNum col_num = lambda x: x.colNum - if compat.mpl_ge_3_4_0: + if compat.mpl_ge_3_4_0(): is_first_col = lambda x: x.get_subplotspec().is_first_col() else: is_first_col = lambda x: x.is_first_col() From 168c3dec5e7f3f1af11a3c785998ad3142f6c96b Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 1 Apr 2021 20:14:50 +0200 Subject: [PATCH 7/7] update test --- pandas/tests/plotting/frame/test_frame.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index 37cd7e4a2641d..e23abc1eee167 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -760,13 +760,10 @@ def test_plot_scatter_with_c(self, request): # default to Greys assert ax.collections[0].cmap.name == "Greys" - # n.b. there appears to be no public method - # to get the colorbar label if mpl_ge_3_4_0(): - mark = pytest.mark.xfail(reason="_label attribute removed") - request.node.add_marker(mark) - - assert ax.collections[0].colorbar._label == "z" + assert ax.collections[0].colorbar.ax.get_ylabel() == "z" + else: + assert ax.collections[0].colorbar._label == "z" cm = "cubehelix" ax = df.plot.scatter(x="x", y="y", c="z", colormap=cm)