Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Doc string changes
  • Loading branch information
topper-123 committed Jun 1, 2019
commit c72758b8e2d24a33ba95abb8d9d032d98268cff4
7 changes: 7 additions & 0 deletions pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ def _constructor(self):

@property
def _data(self):
"""
An int array that for performance reasons is created only when needed.

The constructed array is saved in ``_cached_data``. This allows us to
check if the array has been created without accessing ``_data`` and
triggering the construction.
"""
if self._cached_data is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you give this a doc-string (e.g. that cached_data is actually an int array and be constructed only if necessary for performance reasons

self._cached_data = np.arange(self._start, self._stop, self._step,
dtype=np.int64)
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/indexes/test_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def test_dtype(self):
assert self.index.dtype == np.int64

def test_cached_data(self):
# GH 26565
# Calling RangeIndex._data caches an int64 array of the same length at
# self._cached_data. This tests whether _cached_data has been set.
idx = RangeIndex(0, 100, 10)
Expand Down