Skip to content

PERF: Add short circuiting to RangeIndex._shallow_copy #57534

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 9 commits into from
Feb 20, 2024

Conversation

mroeschke
Copy link
Member

@mroeschke mroeschke commented Feb 20, 2024

xref #57445 (comment)

There needs to be More Work done to attempt to return a RangeIndex, but this should help minimize that Work

@mroeschke mroeschke added Performance Memory or execution speed performance Index Related to the Index class or subclasses labels Feb 20, 2024
@mroeschke mroeschke added this to the 3.0 milestone Feb 20, 2024
diff = values[1] - values[0]
if diff == 0:
return False
curr = values[1]
Copy link
Member

Choose a reason for hiding this comment

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

This is still pretty slow I think, I think what you are looking for is is_range_indexer that we built for CoW with a stepsize argument added

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah gotcha. I refactored to use is_range_indexer

Copy link
Member

Choose a reason for hiding this comment

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

Just to be clear, that will only work with stepsize 1 for now, I am open to support other step sizes as well if you like (follow up should be fine)

Copy link
Member Author

Choose a reason for hiding this comment

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

Right I "normalize" the values by the stepsize (values - values[0] / values[1] - values[0]) so that is_range_indexer can always be used here

Copy link
Member

Choose a reason for hiding this comment

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

Ah sorry, yeah that makes sense

@phofl phofl merged commit 2b82b86 into pandas-dev:main Feb 20, 2024
@phofl
Copy link
Member

phofl commented Feb 20, 2024

thx

@phofl
Copy link
Member

phofl commented Feb 21, 2024

Still a 10% slowdown compared to before, could you check if we can close the gap further?

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