Skip to content

PERF: groupby returns a RangeIndex from groups when possible #58117

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

Closed
wants to merge 3 commits into from

Conversation

mroeschke
Copy link
Member

Discovered in #57441

@mroeschke mroeschke added Groupby Index Related to the Index class or subclasses labels Apr 2, 2024
@mroeschke mroeschke requested a review from rhshadrach as a code owner April 2, 2024 17:11
@@ -754,7 +755,10 @@ def ids(self) -> npt.NDArray[np.intp]:

@cache_readonly
def result_index_and_ids(self) -> tuple[Index, npt.NDArray[np.intp]]:
levels = [Index._with_infer(ping.uniques) for ping in self.groupings]
levels = [
Index._with_infer(maybe_sequence_to_range(ping.uniques))
Copy link
Member

Choose a reason for hiding this comment

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

Is this introducing values-dependent behavior? When grouping is [1, 2, 3] I'd get a RangeIndex but when it's [1, 2, 4] it's now an Index.

If they behave the same and so we can call this an implementation detail, then I'm good not calling this values-dependent behavior.

@mroeschke
Copy link
Member Author

I think #58143 is a more generic application that affects this so closing in favor of that PR

@mroeschke mroeschke closed this Apr 9, 2024
@mroeschke mroeschke deleted the ref/ri/groupby_idx branch April 9, 2024 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby Index Related to the Index class or subclasses
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants