Skip to content

Commit 11b297c

Browse files
authored
CLN: use cache instead of lru_cache for unbound cache (#53462)
1 parent a7eeca3 commit 11b297c

File tree

7 files changed

+15
-18
lines changed

7 files changed

+15
-18
lines changed

pandas/core/_numba/executor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pandas.compat._optional import import_optional_dependency
1515

1616

17-
@functools.lru_cache(maxsize=None)
17+
@functools.cache
1818
def generate_shared_aggregator(
1919
func: Callable[..., Scalar],
2020
nopython: bool,

pandas/core/array_algos/take.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def take_2d_multi(
285285
return out
286286

287287

288-
@functools.lru_cache(maxsize=128)
288+
@functools.lru_cache
289289
def _get_take_nd_function_cached(
290290
ndim: int, arr_dtype: np.dtype, out_dtype: np.dtype, axis: AxisInt
291291
):

pandas/core/dtypes/cast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ def maybe_promote(dtype: np.dtype, fill_value=np.nan):
586586
return dtype, fill_value
587587

588588

589-
@functools.lru_cache(maxsize=128)
589+
@functools.lru_cache
590590
def _maybe_promote_cached(dtype, fill_value, fill_value_type):
591591
# The cached version of _maybe_promote below
592592
# This also use fill_value_type as (unused) argument to use this in the

pandas/core/groupby/numba_.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def f(values, index, ...):
6161
)
6262

6363

64-
@functools.lru_cache(maxsize=None)
64+
@functools.cache
6565
def generate_numba_agg_func(
6666
func: Callable[..., Scalar],
6767
nopython: bool,
@@ -121,7 +121,7 @@ def group_agg(
121121
return group_agg
122122

123123

124-
@functools.lru_cache(maxsize=None)
124+
@functools.cache
125125
def generate_numba_transform_func(
126126
func: Callable[..., np.ndarray],
127127
nopython: bool,

pandas/core/groupby/ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def get_kind_from_how(cls, how: str) -> str:
162162
# Note: we make this a classmethod and pass kind+how so that caching
163163
# works at the class level and not the instance level
164164
@classmethod
165-
@functools.lru_cache(maxsize=None)
165+
@functools.cache
166166
def _get_cython_function(
167167
cls, kind: str, how: str, dtype: np.dtype, is_numeric: bool
168168
):

pandas/core/window/numba_.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from pandas._typing import Scalar
1818

1919

20-
@functools.lru_cache(maxsize=None)
20+
@functools.cache
2121
def generate_numba_apply_func(
2222
func: Callable[..., Scalar],
2323
nopython: bool,
@@ -77,7 +77,7 @@ def roll_apply(
7777
return roll_apply
7878

7979

80-
@functools.lru_cache(maxsize=None)
80+
@functools.cache
8181
def generate_numba_ewm_func(
8282
nopython: bool,
8383
nogil: bool,
@@ -175,7 +175,7 @@ def ewm(
175175
return ewm
176176

177177

178-
@functools.lru_cache(maxsize=None)
178+
@functools.cache
179179
def generate_numba_table_func(
180180
func: Callable[..., np.ndarray],
181181
nopython: bool,
@@ -241,7 +241,7 @@ def roll_table(
241241
# This function will no longer be needed once numba supports
242242
# axis for all np.nan* agg functions
243243
# https://github.com/numba/numba/issues/1269
244-
@functools.lru_cache(maxsize=None)
244+
@functools.cache
245245
def generate_manual_numpy_nan_agg_with_axis(nan_func):
246246
if TYPE_CHECKING:
247247
import numba
@@ -259,7 +259,7 @@ def nan_agg_with_axis(table):
259259
return nan_agg_with_axis
260260

261261

262-
@functools.lru_cache(maxsize=None)
262+
@functools.cache
263263
def generate_numba_ewm_table_func(
264264
nopython: bool,
265265
nogil: bool,

pandas/io/formats/excel.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
"""
44
from __future__ import annotations
55

6-
from functools import (
7-
lru_cache,
8-
reduce,
9-
)
6+
import functools
107
import itertools
118
import re
129
from typing import (
@@ -193,10 +190,10 @@ def __init__(self, inherited: str | None = None) -> None:
193190
self.inherited = self.compute_css(inherited)
194191
else:
195192
self.inherited = None
196-
# We should avoid lru_cache on the __call__ method.
193+
# We should avoid cache on the __call__ method.
197194
# Otherwise once the method __call__ has been called
198195
# garbage collection no longer deletes the instance.
199-
self._call_cached = lru_cache(maxsize=None)(self._call_uncached)
196+
self._call_cached = functools.cache(self._call_uncached)
200197

201198
compute_css = CSSResolver()
202199

@@ -726,7 +723,7 @@ def _format_header(self) -> Iterable[ExcelCell]:
726723
row = [x if x is not None else "" for x in self.df.index.names] + [
727724
""
728725
] * len(self.columns)
729-
if reduce(lambda x, y: x and y, (x != "" for x in row)):
726+
if functools.reduce(lambda x, y: x and y, (x != "" for x in row)):
730727
gen2 = (
731728
ExcelCell(self.rowcounter, colindex, val, self.header_style)
732729
for colindex, val in enumerate(row)

0 commit comments

Comments
 (0)