Skip to content

Commit

Permalink
Address other failures
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Dec 17, 2024
1 parent 7dbf965 commit 369581e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pandas/plotting/_matplotlib/boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import pandas as pd
import pandas.core.common as com
from pandas.util.version import Version

from pandas.io.formats.printing import pprint_thing
from pandas.plotting._matplotlib.core import (
Expand Down Expand Up @@ -54,7 +55,8 @@ def _set_ticklabels(ax: Axes, labels: list[str], is_vertical: bool, **kwargs) ->
ticks = ax.get_xticks() if is_vertical else ax.get_yticks()
if len(ticks) != len(labels):
i, remainder = divmod(len(ticks), len(labels))
assert remainder == 0, remainder
if Version(mpl.__version__) < Version("3.10"):
assert remainder == 0, remainder
labels *= i
if is_vertical:
ax.set_xticklabels(labels, **kwargs)
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/plotting/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,7 @@ def test_boxplot_vertical(self, hist_df):
assert len(ax.lines) == 7 * len(numeric_cols)

@pytest.mark.filterwarnings("ignore:Attempt:UserWarning")
@pytest.mark.filterwarnings("ignore:set_ticklabels:UserWarning")
def test_boxplot_vertical_subplots(self, hist_df):
df = hist_df
numeric_cols = df._get_numeric_data().columns
Expand Down
14 changes: 10 additions & 4 deletions pandas/tests/plotting/test_boxplot_method.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test cases for .boxplot method"""

from __future__ import annotations

import itertools
import string

Expand Down Expand Up @@ -37,7 +39,7 @@ def _check_ax_limits(col, ax):


if Version(mpl.__version__) < Version("3.10"):
verts = [{"vert": False}, {"vert": True}]
verts: list[dict[str, bool | str]] = [{"vert": False}, {"vert": True}]
else:
verts = [{"orientation": "horizontal"}, {"orientation": "vertical"}]

Expand Down Expand Up @@ -337,6 +339,7 @@ def test_plot_xlabel_ylabel(self, vert):
assert ax.get_xlabel() == xlabel
assert ax.get_ylabel() == ylabel

@pytest.mark.filterwarnings("ignore:set_ticklabels:UserWarning")
def test_plot_box(self, vert):
# GH 54941
rng = np.random.default_rng(2)
Expand Down Expand Up @@ -378,7 +381,6 @@ def test_boxplot_group_xlabel_ylabel(self, vert):
assert subplot.get_xlabel() == xlabel
assert subplot.get_ylabel() == ylabel

@pytest.mark.parametrize("vert", [True, False])
def test_boxplot_group_no_xlabel_ylabel(self, vert):
df = DataFrame(
{
Expand All @@ -387,9 +389,13 @@ def test_boxplot_group_no_xlabel_ylabel(self, vert):
"group": np.random.default_rng(2).choice(["group1", "group2"], 10),
}
)
ax = df.boxplot(by="group", vert=vert)
ax = df.boxplot(by="group", **vert)
for subplot in ax:
target_label = subplot.get_xlabel() if vert else subplot.get_ylabel()
target_label = (
subplot.get_xlabel()
if vert == {"vert": True} or vert == {"orientation": "vertical"}
else subplot.get_ylabel()
)
assert target_label == pprint_thing(["group"])


Expand Down

0 comments on commit 369581e

Please sign in to comment.