Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,7 @@ Other
- Bug in ``divmod`` and ``rdivmod`` with :class:`DataFrame`, :class:`Series`, and :class:`Index` with ``bool`` dtypes failing to raise, which was inconsistent with ``__floordiv__`` behavior (:issue:`46043`)
- Bug in printing a :class:`DataFrame` with a :class:`DataFrame` stored in :attr:`DataFrame.attrs` raised a ``ValueError`` (:issue:`60455`)
- Bug in printing a :class:`Series` with a :class:`DataFrame` stored in :attr:`Series.attrs` raised a ``ValueError`` (:issue:`60568`)
- Bug in :class: `BoxPlot` when column order was not respected in ticklabels. (:issue: `50427`)
- Bug when calling :py:func:`copy.copy` on a :class:`DataFrame` or :class:`Series` which would return a deep copy instead of a shallow copy (:issue:`62971`)
- Deprecated the keyword ``check_datetimelike_compat`` in :meth:`testing.assert_frame_equal` and :meth:`testing.assert_series_equal` (:issue:`55638`)
- Fixed bug in :meth:`Series.replace` and :meth:`DataFrame.replace` when trying to replace :class:`NA` values in a :class:`Float64Dtype` object with ``np.nan``; this now works with ``pd.set_option("mode.nan_is_na", False)`` and is irrelevant otherwise (:issue:`55127`)
Expand Down
7 changes: 4 additions & 3 deletions pandas/plotting/_matplotlib/boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ def _make_plot(self, fig: Figure) -> None:

# When `by` is assigned, the ticklabels will become unique grouped
# values, instead of label which is used as subtitle in this case.
# error: "Index" has no attribute "levels"; maybe "nlevels"?
levels = self.data.columns.levels # type: ignore[attr-defined]
ticklabels = [pprint_thing(col) for col in levels[0]]
ticklabels = [
pprint_thing(col)
for col in self.data.columns.get_level_values(0)
]
else:
ticklabels = [pprint_thing(label)]

Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/plotting/test_boxplot_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest

from pandas import (
Categorical,
DataFrame,
MultiIndex,
Series,
Expand Down Expand Up @@ -408,6 +409,20 @@ def test_boxplot_group_no_xlabel_ylabel(self, vert, request):
)
assert target_label == pprint_thing(["group"])

@pytest.mark.filterwarnings("ignore:set_ticklabels:UserWarning")
def test_boxplot_group_ordered_ticklabel(self, vert):
# GH 50427
df = DataFrame(
{
"value": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"label": ["c", "c", "c", "c", "b", "b", "b", "b", "a", "a"],
}
)
df.label = Categorical(df.label, categories=["c", "b", "a"], ordered=True)
ax = df.boxplot(by="label")
xticklabels = ax.get_xticklabels()
assert [x.get_text() for x in xticklabels] == ["c", "b", "a"]


class TestDataFrameGroupByPlots:
def test_boxplot_legacy1(self, hist_df):
Expand Down
Loading