Skip to content

Commit 241bf69

Browse files
Move checks from test_cache_after_calling_loc_with_array to test_cache
1 parent bc9d3b8 commit 241bf69

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

pandas/tests/indexes/ranges/test_range.py

+10-18
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def test_dtype(self, simple_index):
210210
assert index.dtype == np.int64
211211

212212
def test_cache(self):
213-
# GH 26565, GH26617, GH35432
213+
# GH 26565, GH26617, GH35432, GH53387
214214
# This test checks whether _cache has been set.
215215
# Calling RangeIndex._cache["_data"] creates an int64 array of the same length
216216
# as the RangeIndex and stores it in _cache.
@@ -264,23 +264,7 @@ def test_cache(self):
264264
df.iloc[5:10]
265265
assert idx._cache == {}
266266

267-
# idx._cache should contain a _data entry after call to idx._data
268-
idx._data
269-
assert isinstance(idx._data, np.ndarray)
270-
assert idx._data is idx._data # check cached value is reused
271-
assert len(idx._cache) == 1
272-
expected = np.arange(0, 100, 10, dtype="int64")
273-
tm.assert_numpy_array_equal(idx._cache["_data"], expected)
274-
275-
def test_cache_after_calling_loc_with_array(self):
276-
# GH 53387
277-
# the cache will contain a _constructor key, so it should be tested separately
278-
idx = RangeIndex(0, 100, 10)
279-
df = pd.DataFrame({"a": range(10)}, index=idx)
280-
281-
assert "_data" not in idx._cache
282-
283-
# take is internally called by loc, but it's also tested explicitly
267+
# after calling take, _cache may contain other keys, but not "_data"
284268
idx.take([3, 0, 1])
285269
assert "_data" not in idx._cache
286270

@@ -290,6 +274,14 @@ def test_cache_after_calling_loc_with_array(self):
290274
df.iloc[[5, 6, 7, 8, 9]]
291275
assert "_data" not in idx._cache
292276

277+
# idx._cache should contain a _data entry after call to idx._data
278+
idx._data
279+
assert isinstance(idx._data, np.ndarray)
280+
assert idx._data is idx._data # check cached value is reused
281+
assert "_data" in idx._cache
282+
expected = np.arange(0, 100, 10, dtype="int64")
283+
tm.assert_numpy_array_equal(idx._cache["_data"], expected)
284+
293285
def test_is_monotonic(self):
294286
index = RangeIndex(0, 20, 2)
295287
assert index.is_monotonic_increasing is True

0 commit comments

Comments
 (0)