Skip to content

Backport PR #58992 on branch 2.2.x (PERF: cache plotting date locators for DatetimeIndex plotting) #59002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
12 changes: 8 additions & 4 deletions pandas/plotting/_matplotlib/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ def _get_periods_per_ymd(freq: BaseOffset) -> tuple[int, int, int]:
return ppd, ppm, ppy


def _daily_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray:
@functools.cache
def _daily_finder(vmin: float, vmax: float, freq: BaseOffset) -> np.ndarray:
# error: "BaseOffset" has no attribute "_period_dtype_code"
dtype_code = freq._period_dtype_code # type: ignore[attr-defined]

Expand Down Expand Up @@ -783,7 +784,8 @@ def _second_finder(label_interval: int) -> None:
return info


def _monthly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray:
@functools.cache
def _monthly_finder(vmin: float, vmax: float, freq: BaseOffset) -> np.ndarray:
_, _, periodsperyear = _get_periods_per_ymd(freq)

vmin_orig = vmin
Expand Down Expand Up @@ -854,7 +856,8 @@ def _monthly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray:
return info


def _quarterly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray:
@functools.cache
def _quarterly_finder(vmin: float, vmax: float, freq: BaseOffset) -> np.ndarray:
_, _, periodsperyear = _get_periods_per_ymd(freq)
vmin_orig = vmin
(vmin, vmax) = (int(vmin), int(vmax))
Expand Down Expand Up @@ -901,7 +904,8 @@ def _quarterly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray:
return info


def _annual_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray:
@functools.cache
def _annual_finder(vmin: float, vmax: float, freq: BaseOffset) -> np.ndarray:
# Note: small difference here vs other finders in adding 1 to vmax
(vmin, vmax) = (int(vmin), int(vmax + 1))
span = vmax - vmin + 1
Expand Down
Loading