Skip to content

Commit 99f5cb8

Browse files
authored
REF: Avoid/defer dtype=object containers in plotting (#62042)
1 parent 79cc01d commit 99f5cb8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pandas/plotting/_matplotlib/boxplot.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ def maybe_color_bp(self, bp) -> None:
190190

191191
def _make_plot(self, fig: Figure) -> None:
192192
if self.subplots:
193-
self._return_obj = pd.Series(dtype=object)
193+
obj_axes = []
194+
obj_labels = []
194195

195196
# Re-create iterated data if `by` is assigned by users
196197
data = (
@@ -221,10 +222,12 @@ def _make_plot(self, fig: Figure) -> None:
221222
ax, y, column_num=i, return_type=self.return_type, **kwds
222223
)
223224
self.maybe_color_bp(bp)
224-
self._return_obj[label] = ret
225+
obj_axes.append(ret)
226+
obj_labels.append(label)
225227
_set_ticklabels(
226228
ax=ax, labels=ticklabels, is_vertical=self.orientation == "vertical"
227229
)
230+
self._return_obj = pd.Series(obj_axes, index=obj_labels, dtype=object)
228231
else:
229232
y = self.data.values.T
230233
ax = self._get_ax(0)
@@ -400,7 +403,7 @@ def plot_group(keys, values, ax: Axes, **kwds):
400403
ax.set_ylabel(pprint_thing(ylabel))
401404

402405
keys = [pprint_thing(x) for x in keys]
403-
values = [np.asarray(remove_na_arraylike(v), dtype=object) for v in values]
406+
values = [remove_na_arraylike(v) for v in values]
404407
bp = ax.boxplot(values, **kwds)
405408
if fontsize is not None:
406409
ax.tick_params(axis="both", labelsize=fontsize)

0 commit comments

Comments
 (0)