Skip to content

Commit 0eb84b3

Browse files
Backport PR #58992 on branch 2.2.x (PERF: cache plotting date locators for DatetimeIndex plotting) (#59002)
Backport PR #58992: PERF: cache plotting date locators for DatetimeIndex plotting Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 6fd9558 commit 0eb84b3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pandas/plotting/_matplotlib/converter.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@ def _get_periods_per_ymd(freq: BaseOffset) -> tuple[int, int, int]:
584584
return ppd, ppm, ppy
585585

586586

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

@@ -783,7 +784,8 @@ def _second_finder(label_interval: int) -> None:
783784
return info
784785

785786

786-
def _monthly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray:
787+
@functools.cache
788+
def _monthly_finder(vmin: float, vmax: float, freq: BaseOffset) -> np.ndarray:
787789
_, _, periodsperyear = _get_periods_per_ymd(freq)
788790

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

856858

857-
def _quarterly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray:
859+
@functools.cache
860+
def _quarterly_finder(vmin: float, vmax: float, freq: BaseOffset) -> np.ndarray:
858861
_, _, periodsperyear = _get_periods_per_ymd(freq)
859862
vmin_orig = vmin
860863
(vmin, vmax) = (int(vmin), int(vmax))
@@ -901,7 +904,8 @@ def _quarterly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray:
901904
return info
902905

903906

904-
def _annual_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray:
907+
@functools.cache
908+
def _annual_finder(vmin: float, vmax: float, freq: BaseOffset) -> np.ndarray:
905909
# Note: small difference here vs other finders in adding 1 to vmax
906910
(vmin, vmax) = (int(vmin), int(vmax + 1))
907911
span = vmax - vmin + 1

0 commit comments

Comments
 (0)