Add value counts aggregation to select.group_by - #1114
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new counts aggregation option to select.group_by so grouped recipes can return per-value frequency distributions (as JSON-safe dictionaries) instead of only scalar aggregates.
Changes:
- Extend
select.group_byto support acountsaggregation that returns{value_as_string: frequency}per group. - Normalize keys for JSON-safety (string conversion, lowercase boolean strings, and a
"null"key for missing values). - Add a unit test validating the new aggregation and per-column output renaming with
auto_rename_columns: false.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
wrangles/recipe_wrangles/select.py |
Adds schema documentation and implements the counts aggregation using value_counts(dropna=False) with JSON-safe key normalization. |
tests/recipes/wrangles/test_select.py |
Adds a test covering counts output structure and column renaming behavior. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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
countsaggregation toselect.group_bynulland booleans as lowercasetrueorfalseWhy
Grouped recipes sometimes need the distribution of values within each group rather than only a scalar count or a list of the original values. Without this aggregation, recipes need additional transformations to construct a value-to-frequency mapping.
Impact
Recipes can now request value counts directly:
The resulting
Selection Countsvalue is a JSON-safe dictionary such as{"Primary": 2, "None": 1}.Validation
TestGroupByclass:30 passedgit diff --checkpassedSyntaxWarningwarnings were emitted; no test failures