Skip to content

Commit 2b45ac9

Browse files
committed
Fix: Remove decorate_axes call to avoid _plot_data attribute on bar plots
Bar plots should not have _plot_data attribute. Instead of calling decorate_axes() which initializes _plot_data, we manually set freq on the axis and xaxis objects only, which is sufficient for the formatter to work properly. This fixes test_memory_leak[bar] and test_memory_leak[barh] failures.
1 parent f73aca0 commit 2b45ac9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pandas/plotting/_matplotlib/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
from pandas.plotting._matplotlib.misc import unpack_single_str_list
6767
from pandas.plotting._matplotlib.style import get_standard_colors
6868
from pandas.plotting._matplotlib.timeseries import (
69-
decorate_axes,
7069
format_dateaxis,
7170
maybe_convert_index,
7271
prepare_ts_data,
@@ -2047,8 +2046,12 @@ def _post_plot_logic(self, ax: Axes, data) -> None:
20472046

20482047
# GH#1918: Apply date formatter for time series indices
20492048
if self._is_ts_plot():
2050-
decorate_axes(ax, data.index.freq)
20512049
freq = data.index.freq
2050+
# Set freq on axis for formatter to use, but don't call decorate_axes
2051+
# to avoid adding _plot_data attribute (which bar plots shouldn't have)
2052+
ax.freq = freq # type: ignore[attr-defined]
2053+
xaxis = ax.get_xaxis()
2054+
xaxis.freq = freq # type: ignore[attr-defined]
20522055

20532056
index = data.index
20542057
if isinstance(index, ABCDatetimeIndex):

0 commit comments

Comments
 (0)