Skip to content

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

Merged
merged 26 commits into from
Mar 19, 2024

Conversation

mroeschke
Copy link
Member

Discovered in #57441

Builds on #57752

@mroeschke mroeschke added Performance Memory or execution speed performance Index Related to the Index class or subclasses labels Mar 8, 2024
@mroeschke mroeschke added this to the 3.0 milestone Mar 9, 2024
-------
Any : input or range
"""
if hasattr(sequence, "dtype") and not isinstance(sequence, np.ndarray):
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member Author

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]
Copy link
Member

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?

Copy link
Member Author

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

@mroeschke
Copy link
Member Author

Any other comments here @WillAyd?

@WillAyd
Copy link
Member

WillAyd commented Mar 19, 2024

Nope all good. And thanks for the ping - sorry sometimes fall behind on notifications

@WillAyd WillAyd merged commit 38086f1 into pandas-dev:main Mar 19, 2024
46 checks passed
@mroeschke mroeschke deleted the perf/ri/ensure_index_from_sequence branch March 19, 2024 20:37
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Index Related to the Index class or subclasses Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants