-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN/PERF: move RangeIndex._cached_data to RangeIndex._cache #35432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLN/PERF: move RangeIndex._cached_data to RangeIndex._cache #35432
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. @jbrockmendel if you can give a glance
@topper-123 can you rebase |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we ever do this check outside of tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, and the checks in the tests are to ensure this array isn't created unless it's needed.
LGTM pending rebase+green |
7bea094
to
f24b28f
Compare
The
._cached_data
attribute is not necessary. It was originally added to allow a check to see if the._data
ndarray had been created, but that's also possible to do by a"_data" in _cache
check in the new implemention, which IMO would be more idiomatic.The new implementation has the benefit that the
_data
will be available to new copies of a RangeIndex, saving the need to create a new ndarray for each new copy of the RangeIndex.xref #26565.