-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PERF: Allow ensure_index_from_sequence to return RangeIndex #57786
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
PERF: Allow ensure_index_from_sequence to return RangeIndex #57786
Conversation
pandas/core/indexes/base.py
Outdated
------- | ||
Any : input or range | ||
""" | ||
if hasattr(sequence, "dtype") and not isinstance(sequence, np.ndarray): |
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.
I find the duck typing here somewhat non-obvious - maybe comments will help? Is this first branch supposed to be for extension types?
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.
Is this first branch supposed to be for extension types?
Essentially yes, I think I can use a more specific check here
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.
Updated the check here to be more explicit (exclude Series and Index objects)
return sequence | ||
elif len(sequence) == 0: | ||
return range(0) | ||
diff = np_sequence[1] - np_sequence[0] |
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.
Why are only the first two elements important here?
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.
We're taking an example diff here (just between the first 2 elements) and later seeing if the rest of the diffs between the rest of the elements match
Any other comments here @WillAyd? |
Nope all good. And thanks for the ping - sorry sometimes fall behind on notifications |
Discovered in #57441
Builds on #57752