fix(python): Raise TypeError on GroupBy next() call#27324
Open
yosofbadr wants to merge 3 commits intopola-rs:mainfrom
Open
fix(python): Raise TypeError on GroupBy next() call#27324yosofbadr wants to merge 3 commits intopola-rs:mainfrom
yosofbadr wants to merge 3 commits intopola-rs:mainfrom
Conversation
Extract iteration state into a separate _GroupByIter class so that GroupBy, RollingGroupBy, and DynamicGroupBy no longer implement __next__ directly. This means calling next() on a GroupBy object without first calling iter() now raises a clear TypeError instead of an AttributeError about a missing _current_index attribute. Closes pola-rs#12868
- Sort __slots__ alphabetically in _GroupByIter (RUF023) - Add type: ignore[call-overload] for intentional next(GroupBy) test
The coverage-rust job timed out after 37 minutes; our change is Python-only and unrelated to Rust coverage.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
next()on aGroupByobject raisingAttributeError: 'GroupBy' object has no attribute '_current_index'instead of a properTypeError._GroupByIterclass.GroupBy.__iter__()now returns a_GroupByIterinstance instead ofself, so theGroupByclass itself no longer implements__next__. This meansnext(df.group_by(...))raisesTypeError: 'GroupBy' object is not an iterator, matching standard Python iterator protocol behavior.RollingGroupByandDynamicGroupBywhich had the identical issue.Closes #12868
Test plan
test_group_by_next_raises_type_error_12868to verifynext()on aGroupByraisesTypeErrortest_group_by_iterationtests should continue passing (iteration viaforloop anditer()still works)test_group_by_all_12869which usesnext(iter(...))pattern should pass