@@ -210,7 +210,7 @@ def test_dtype(self, simple_index):
210
210
assert index .dtype == np .int64
211
211
212
212
def test_cache (self ):
213
- # GH 26565, GH26617, GH35432
213
+ # GH 26565, GH26617, GH35432, GH53387
214
214
# This test checks whether _cache has been set.
215
215
# Calling RangeIndex._cache["_data"] creates an int64 array of the same length
216
216
# as the RangeIndex and stores it in _cache.
@@ -264,23 +264,7 @@ def test_cache(self):
264
264
df .iloc [5 :10 ]
265
265
assert idx ._cache == {}
266
266
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"
284
268
idx .take ([3 , 0 , 1 ])
285
269
assert "_data" not in idx ._cache
286
270
@@ -290,6 +274,14 @@ def test_cache_after_calling_loc_with_array(self):
290
274
df .iloc [[5 , 6 , 7 , 8 , 9 ]]
291
275
assert "_data" not in idx ._cache
292
276
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
+
293
285
def test_is_monotonic (self ):
294
286
index = RangeIndex (0 , 20 , 2 )
295
287
assert index .is_monotonic_increasing is True
0 commit comments