@@ -241,35 +241,40 @@ def test_view(self):
241
241
def test_dtype (self ):
242
242
assert self .index .dtype == np .int64
243
243
244
- def test_has_called_data (self ):
245
- # Calling RangeIndex._data caches a array of the same length.
246
- # This tests whether RangeIndex._data has been called by doing methods
244
+ def test_cached_data (self ):
245
+ # Calling RangeIndex._data caches an int64 array of the same length at
246
+ # self._cached_data. This tests whether _cached_data has been set.
247
247
idx = RangeIndex (0 , 100 , 10 )
248
- assert idx ._has_called_data is False
248
+
249
+ assert idx ._cached_data is None
249
250
250
251
repr (idx )
251
- assert idx ._has_called_data is False
252
+ assert idx ._cached_data is None
252
253
253
254
str (idx )
254
- assert idx ._has_called_data is False
255
+ assert idx ._cached_data is None
255
256
256
257
idx .get_loc (20 )
257
- assert idx ._has_called_data is False
258
+ assert idx ._cached_data is None
258
259
259
260
df = pd .DataFrame ({'a' : range (10 )}, index = idx )
260
261
261
262
df .loc [50 ]
262
- assert idx ._has_called_data is False
263
+ assert idx ._cached_data is None
263
264
264
265
with pytest .raises (KeyError ):
265
266
df .loc [51 ]
266
- assert idx ._has_called_data is False
267
+ assert idx ._cached_data is None
267
268
268
269
df .loc [10 :50 ]
269
- assert idx ._has_called_data is False
270
+ assert idx ._cached_data is None
270
271
271
272
df .iloc [5 :10 ]
272
- assert idx ._has_called_data is False
273
+ assert idx ._cached_data is None
274
+
275
+ # actually calling data._data
276
+ assert isinstance (idx ._data , np .ndarray )
277
+ assert isinstance (idx ._cached_data , np .ndarray )
273
278
274
279
def test_is_monotonic (self ):
275
280
assert self .index .is_monotonic is True
0 commit comments