Skip to content

Commit 5b8952d

Browse files
authored
CLN: Minor cleanup of caching (#40225)
1 parent c7d3e9b commit 5b8952d

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

pandas/core/base.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class PandasObject(DirNamesMixin):
8080
Baseclass for various pandas objects.
8181
"""
8282

83+
# results from calls to methods decorated with cache_readonly get added to _cache
8384
_cache: Dict[str, Any]
8485

8586
@property
@@ -100,14 +101,14 @@ def _reset_cache(self, key: Optional[str] = None) -> None:
100101
"""
101102
Reset cached properties. If ``key`` is passed, only clears that key.
102103
"""
103-
if getattr(self, "_cache", None) is None:
104+
if not hasattr(self, "_cache"):
104105
return
105106
if key is None:
106107
self._cache.clear()
107108
else:
108109
self._cache.pop(key, None)
109110

110-
def __sizeof__(self):
111+
def __sizeof__(self) -> int:
111112
"""
112113
Generates the total memory usage for an object that returns
113114
either a value or Series of values

pandas/core/indexes/range.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def _format_with_header(self, header: List[str], na_rep: str = "NaN") -> List[st
238238
"instead"
239239
)
240240

241-
@cache_readonly
241+
@property
242242
def start(self):
243243
"""
244244
The value of the `start` parameter (``0`` if this was not supplied).
@@ -261,7 +261,7 @@ def _start(self):
261261
)
262262
return self.start
263263

264-
@cache_readonly
264+
@property
265265
def stop(self):
266266
"""
267267
The value of the `stop` parameter.
@@ -284,7 +284,7 @@ def _stop(self):
284284
)
285285
return self.stop
286286

287-
@cache_readonly
287+
@property
288288
def step(self):
289289
"""
290290
The value of the `step` parameter (``1`` if this was not supplied).

pandas/tests/indexes/ranges/test_range.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def test_cache(self):
203203
idx._data
204204
assert isinstance(idx._data, np.ndarray)
205205
assert idx._data is idx._data # check cached value is reused
206-
assert len(idx._cache) == 4
206+
assert len(idx._cache) == 1
207207
expected = np.arange(0, 100, 10, dtype="int64")
208208
tm.assert_numpy_array_equal(idx._cache["_data"], expected)
209209

0 commit comments

Comments
 (0)