From 6dcdd83098342a912a52b1451d3bfb303b8c9030 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 12 Jun 2024 15:47:05 -0700 Subject: [PATCH 1/2] PERF: cache plotting date locators for DatetimeIndex plotting --- pandas/plotting/_matplotlib/converter.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/plotting/_matplotlib/converter.py b/pandas/plotting/_matplotlib/converter.py index a8f08769ceae2..6b7b4293c9427 100644 --- a/pandas/plotting/_matplotlib/converter.py +++ b/pandas/plotting/_matplotlib/converter.py @@ -556,6 +556,7 @@ def _get_periods_per_ymd(freq: BaseOffset) -> tuple[int, int, int]: return ppd, ppm, ppy +@functools.cache def _daily_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray: # error: "BaseOffset" has no attribute "_period_dtype_code" dtype_code = freq._period_dtype_code # type: ignore[attr-defined] @@ -755,6 +756,7 @@ def _second_finder(label_interval: int) -> None: return info +@functools.cache def _monthly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray: _, _, periodsperyear = _get_periods_per_ymd(freq) @@ -826,6 +828,7 @@ def _monthly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray: return info +@functools.cache def _quarterly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray: _, _, periodsperyear = _get_periods_per_ymd(freq) vmin_orig = vmin @@ -873,6 +876,7 @@ def _quarterly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray: return info +@functools.cache def _annual_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray: # Note: small difference here vs other finders in adding 1 to vmax (vmin, vmax) = (int(vmin), int(vmax + 1)) From efec20f8ae887f789e66111d754adbe348a50b28 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 13 Jun 2024 08:20:11 -0700 Subject: [PATCH 2/2] Type vmin, vmax --- pandas/plotting/_matplotlib/converter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/plotting/_matplotlib/converter.py b/pandas/plotting/_matplotlib/converter.py index 6b7b4293c9427..fc63d65f1e160 100644 --- a/pandas/plotting/_matplotlib/converter.py +++ b/pandas/plotting/_matplotlib/converter.py @@ -557,7 +557,7 @@ def _get_periods_per_ymd(freq: BaseOffset) -> tuple[int, int, int]: @functools.cache -def _daily_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray: +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] @@ -757,7 +757,7 @@ def _second_finder(label_interval: int) -> None: @functools.cache -def _monthly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray: +def _monthly_finder(vmin: float, vmax: float, freq: BaseOffset) -> np.ndarray: _, _, periodsperyear = _get_periods_per_ymd(freq) vmin_orig = vmin @@ -829,7 +829,7 @@ def _monthly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray: @functools.cache -def _quarterly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray: +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)) @@ -877,7 +877,7 @@ def _quarterly_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray: @functools.cache -def _annual_finder(vmin, vmax, freq: BaseOffset) -> np.ndarray: +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