fix(python): Allow list argument in group_by().map_groups()#26707
Merged
nameexhaustion merged 4 commits intopola-rs:mainfrom Mar 10, 2026
Merged
fix(python): Allow list argument in group_by().map_groups()#26707nameexhaustion merged 4 commits intopola-rs:mainfrom
group_by().map_groups()#26707nameexhaustion merged 4 commits intopola-rs:mainfrom
Conversation
When `group_by` receives a list of column names (e.g. `df.group_by(['a', 'b'])`), `self.by` is stored as `(['a', 'b'],)`. The `map_groups` method checked `isinstance(c, str) for c in self.by` which found the list element and raised TypeError. Fix: flatten `self.by` via `_parse_inputs_as_iterable` (already used elsewhere) before the string check, consistent with how other GroupBy methods handle the variadic `*by` parameter. Fixes pola-rs#26672
group_by().map_groups()group_by().map_groups()
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #26707 +/- ##
==========================================
+ Coverage 81.00% 81.66% +0.66%
==========================================
Files 1805 1805
Lines 248021 248090 +69
Branches 3132 3131 -1
==========================================
+ Hits 200902 202612 +1710
+ Misses 46313 44673 -1640
+ Partials 806 805 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
nameexhaustion
approved these changes
Mar 10, 2026
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.
Fixes #26672
Summary
df.group_by(['a', 'b']).map_groups(lambda df: df)raisesTypeError: cannot callmap_groupswhen grouping by an expression, even though all elements are plain column name strings.Root Cause
group_byaccepts*by(variadic), sodf.group_by(['a', 'b'])storesself.by = (['a', 'b'],). The checkisinstance(c, str) for c in self.byiterates over the outer tuple and finds a list, not a string.Fix
Flatten
self.byvia_parse_inputs_as_iterable(already imported and used elsewhere in the module) before the string check. This is consistent with how other methods handle the variadic*byparameter.As @ritchie46 noted in the issue, the check was overly strict — a list of strings is a perfectly valid input.
Test
Added
test_map_groups_group_by_list_26672verifying bothgroup_by(['a', 'b'])andgroup_by('a', 'b')work withmap_groups.