PERF: Return RangeIndex from RangeIndex.reindex when possible by mroeschke · Pull Request #57647 · pandas-dev/pandas (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation5 Commits14 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

mroeschke

@mroeschke

@mroeschke

@datapythonista

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

@mroeschke

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

datapythonista

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)

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.

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

datapythonista

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.

pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request

May 7, 2024

@mroeschke @pmhatre1

…-dev#57647)

Labels

Index

Related to the Index class or subclasses

Performance

Memory or execution speed performance

2 participants

@mroeschke @datapythonista