diff --git a/pandas/core/base.py b/pandas/core/base.py index 9b2efeff76926..86f5a7cae3693 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -80,6 +80,7 @@ class PandasObject(DirNamesMixin): Baseclass for various pandas objects. """ + # results from calls to methods decorated with cache_readonly get added to _cache _cache: Dict[str, Any] @property @@ -100,14 +101,14 @@ def _reset_cache(self, key: Optional[str] = None) -> None: """ Reset cached properties. If ``key`` is passed, only clears that key. """ - if getattr(self, "_cache", None) is None: + if not hasattr(self, "_cache"): return if key is None: self._cache.clear() else: self._cache.pop(key, None) - def __sizeof__(self): + def __sizeof__(self) -> int: """ Generates the total memory usage for an object that returns either a value or Series of values diff --git a/pandas/core/indexes/range.py b/pandas/core/indexes/range.py index a0f546a6bd748..5d1716e514ec1 100644 --- a/pandas/core/indexes/range.py +++ b/pandas/core/indexes/range.py @@ -238,7 +238,7 @@ def _format_with_header(self, header: List[str], na_rep: str = "NaN") -> List[st "instead" ) - @cache_readonly + @property def start(self): """ The value of the `start` parameter (``0`` if this was not supplied). @@ -261,7 +261,7 @@ def _start(self): ) return self.start - @cache_readonly + @property def stop(self): """ The value of the `stop` parameter. @@ -284,7 +284,7 @@ def _stop(self): ) return self.stop - @cache_readonly + @property def step(self): """ The value of the `step` parameter (``1`` if this was not supplied). diff --git a/pandas/tests/indexes/ranges/test_range.py b/pandas/tests/indexes/ranges/test_range.py index fb670c508a8f1..3d36e03751f95 100644 --- a/pandas/tests/indexes/ranges/test_range.py +++ b/pandas/tests/indexes/ranges/test_range.py @@ -203,7 +203,7 @@ def test_cache(self): idx._data assert isinstance(idx._data, np.ndarray) assert idx._data is idx._data # check cached value is reused - assert len(idx._cache) == 4 + assert len(idx._cache) == 1 expected = np.arange(0, 100, 10, dtype="int64") tm.assert_numpy_array_equal(idx._cache["_data"], expected)