Skip to content
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: Return RangeIndex from RangeIndex.reindex when possible #57647

Merged
merged 14 commits into from
Mar 5, 2024

Conversation

mroeschke
Copy link
Member

Discovered in #57441

@mroeschke mroeschke added Performance Memory or execution speed performance Index Related to the Index class or subclasses labels Feb 27, 2024
@mroeschke mroeschke added this to the 3.0 milestone Feb 27, 2024
@datapythonista
Copy link
Member

I think something went wrong with git here, feels like this have unrelated changes, right?

@mroeschke
Copy link
Member Author

As of 1a12235, I think the diff against main should be minimal to the changes now. (In 370d20c I merged upstream incorrectly)

tm.assert_index_equal(result, expected, exact=True)

expected_indexer = np.array([1, -1, -1], dtype=np.intp)
tm.assert_numpy_array_equal(result_indexer, expected_indexer)
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to add a test case when RangeIndex can't be returned? Like, if we call ri.reindex([1, 3, 9]) my expectation is that it should still return Index, which I guess it does, but I wonder whether your changes can make it raise instead. I think it'd be good to have a test for that, and I couldn't find one already in the test suite.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure added a test in the same file where RangeIndex.reindex will return an Index

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

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

Amazing, looks perfect to me.

@mroeschke mroeschke merged commit 0be8f98 into pandas-dev:main Mar 5, 2024
47 checks passed
@mroeschke mroeschke deleted the perf/ri/reindex_return branch March 5, 2024 23:03
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
…-dev#57647)

* PERF: Return RangeIndex from RangeIndex.reindex when possible

* Add whatsnew number

* Only if index

* add name

* Skip for type self, undo test

* Use intp

* merge

* Add test for Index return
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