From f624b64bd3619186a85987022b15bb2d7c219ccc Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 4 Aug 2025 10:10:04 -0700 Subject: [PATCH 1/3] Avoid dtype=object in group plotting --- pandas/plotting/_matplotlib/boxplot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/plotting/_matplotlib/boxplot.py b/pandas/plotting/_matplotlib/boxplot.py index af77972da8634..340ee2f6b2580 100644 --- a/pandas/plotting/_matplotlib/boxplot.py +++ b/pandas/plotting/_matplotlib/boxplot.py @@ -400,7 +400,7 @@ def plot_group(keys, values, ax: Axes, **kwds): ax.set_ylabel(pprint_thing(ylabel)) keys = [pprint_thing(x) for x in keys] - values = [np.asarray(remove_na_arraylike(v), dtype=object) for v in values] + values = [remove_na_arraylike(v) for v in values] bp = ax.boxplot(values, **kwds) if fontsize is not None: ax.tick_params(axis="both", labelsize=fontsize) From 62645c0236ca1fc5a9244ab1d3608539aff5f18c Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 4 Aug 2025 10:40:10 -0700 Subject: [PATCH 2/3] Conver to Series at the end --- pandas/plotting/_matplotlib/boxplot.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/plotting/_matplotlib/boxplot.py b/pandas/plotting/_matplotlib/boxplot.py index 340ee2f6b2580..40277a1128b08 100644 --- a/pandas/plotting/_matplotlib/boxplot.py +++ b/pandas/plotting/_matplotlib/boxplot.py @@ -190,7 +190,8 @@ def maybe_color_bp(self, bp) -> None: def _make_plot(self, fig: Figure) -> None: if self.subplots: - self._return_obj = pd.Series(dtype=object) + axes = [] + labels = [] # Re-create iterated data if `by` is assigned by users data = ( @@ -221,10 +222,12 @@ def _make_plot(self, fig: Figure) -> None: ax, y, column_num=i, return_type=self.return_type, **kwds ) self.maybe_color_bp(bp) - self._return_obj[label] = ret + axes.append(ret) + labels.append(label) _set_ticklabels( ax=ax, labels=ticklabels, is_vertical=self.orientation == "vertical" ) + self._return_obj = pd.Series(axes, index=labels, dtype=object) else: y = self.data.values.T ax = self._get_ax(0) From fbbca5c924c83fed4424416d7067626ee9113bfa Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 4 Aug 2025 13:35:27 -0700 Subject: [PATCH 3/3] Rename variable for typing --- pandas/plotting/_matplotlib/boxplot.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/plotting/_matplotlib/boxplot.py b/pandas/plotting/_matplotlib/boxplot.py index 40277a1128b08..32b1fbe73a310 100644 --- a/pandas/plotting/_matplotlib/boxplot.py +++ b/pandas/plotting/_matplotlib/boxplot.py @@ -190,8 +190,8 @@ def maybe_color_bp(self, bp) -> None: def _make_plot(self, fig: Figure) -> None: if self.subplots: - axes = [] - labels = [] + obj_axes = [] + obj_labels = [] # Re-create iterated data if `by` is assigned by users data = ( @@ -222,12 +222,12 @@ def _make_plot(self, fig: Figure) -> None: ax, y, column_num=i, return_type=self.return_type, **kwds ) self.maybe_color_bp(bp) - axes.append(ret) - labels.append(label) + obj_axes.append(ret) + obj_labels.append(label) _set_ticklabels( ax=ax, labels=ticklabels, is_vertical=self.orientation == "vertical" ) - self._return_obj = pd.Series(axes, index=labels, dtype=object) + self._return_obj = pd.Series(obj_axes, index=obj_labels, dtype=object) else: y = self.data.values.T ax = self._get_ax(0)