Skip to content

Commit 566e592

Browse files
authored
PERF: cache plotting date locators for DatetimeIndex plotting (#58992)
* PERF: cache plotting date locators for DatetimeIndex plotting * Type vmin, vmax
1 parent 54cf59b commit 566e592

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
@@ -556,7 +556,8 @@ def _get_periods_per_ymd(freq: BaseOffset) -> tuple[int, int, int]:
556556
return ppd, ppm, ppy
557557

558558

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

@@ -755,7 +756,8 @@ def _second_finder(label_interval: int) -> None:
755756
return info
756757

757758

758-
def _monthly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray:
759+
@functools.cache
760+
def _monthly_finder(vmin: float, vmax: float, freq: BaseOffset) -> np.ndarray:
759761
_, _, periodsperyear = _get_periods_per_ymd(freq)
760762

761763
vmin_orig = vmin
@@ -826,7 +828,8 @@ def _monthly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray:
826828
return info
827829

828830

829-
def _quarterly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray:
831+
@functools.cache
832+
def _quarterly_finder(vmin: float, vmax: float, freq: BaseOffset) -> np.ndarray:
830833
_, _, periodsperyear = _get_periods_per_ymd(freq)
831834
vmin_orig = vmin
832835
(vmin, vmax) = (int(vmin), int(vmax))
@@ -873,7 +876,8 @@ def _quarterly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray:
873876
return info
874877

875878

876-
def _annual_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray:
879+
@functools.cache
880+
def _annual_finder(vmin: float, vmax: float, freq: BaseOffset) -> np.ndarray:
877881
# Note: small difference here vs other finders in adding 1 to vmax
878882
(vmin, vmax) = (int(vmin), int(vmax + 1))
879883
span = vmax - vmin + 1

0 commit comments

Comments
 (0)