Repository navigation
[Datasets] Multi-aggregations [1/3]: Add basic support for groupby multi-aggregations. - #20044
Merged
ericl merged 4 commits intoNov 5, 2021
Conversation
jjyao
reviewed
Nov 4, 2021
jjyao
reviewed
Nov 4, 2021
jjyao
reviewed
Nov 4, 2021
Merged
3 of 6 tasks
jjyao
approved these changes
Nov 4, 2021
ericl
reviewed
Nov 4, 2021
| >>> ray.data.range(100).aggregate(Max()) | ||
| >>> ray.data.range_arrow(100).aggregate(Max("value")) | ||
| >>> ray.data.range_arrow(100).aggregate( | ||
| Max("value"), Mean("value")) |
Contributor
There was a problem hiding this comment.
Should we mark our built-in agg as part of the PublicAPI as well? (add to docs, etc.?)
Contributor
Author
There was a problem hiding this comment.
Definitely! I'm planning on adding that in the third stacked PR, since we'll have the full API at that point (nicest UX).
Contributor
Author
|
Datasets tests are passing, looks good to merge |
ericl
approved these changes
Nov 5, 2021
goutamvenkat-anyscale
pushed a commit
that referenced
this pull request
Sep 18, 2026
…names (#66218) ## Why Two bugs in `TableBlockAccessor`'s aggregation path, both visible from the public API. **A global aggregation over an empty dataset returns `None`.** ```python ray.data.range(10).filter(lambda row: False).aggregate(Count()) # before: None # after: {'count()': 0} ``` #66194 added an early return for zero-row blocks. That is right for a keyed aggregation — no rows means no groups — but a global aggregation always has exactly one group, and still owes its identity row. Counting an empty dataset is `0`, not "no answer". **Repeated aggregations overwrite each other's results.** ```python ray.data.range(4).aggregate(Sum("id"), Sum("id"), Sum("id")) # before: {'sum(id)': 6, 'sum(id)_2': 6} # after: {'sum(id)': 6, 'sum(id)_2': 6, 'sum(id)_3': 6} ``` `_resolve_aggregated_column_names` suffixes duplicate names, but incremented the counter for the *suffixed* name rather than the original. The original's count never advanced past one, so every duplicate after the first resolved to `_2` again. Because `_aggregate` builds rows with `row[name] = accumulator`, two aggregations sharing a name means one result is silently dropped. ## What changes - The empty-block early return in `_aggregate` is gated on there being group keys, and the `num_rows() > 0` check around `accumulate_block` is restored, so an empty group leaves the accumulators at their identity values. - `_resolve_aggregated_column_names` counts the original name and suffixes until the name is free. Looping rather than suffixing once also covers a generated suffix colliding with an aggregation explicitly named that, as in `["a", "a_2", "a"]`. It now takes the names rather than the aggregations, since that is all it reads. - `GPUAggregationPlan` carried its own copy of that loop, which resolved names differently from the CPU path — the same query returned different column names depending on the shuffle strategy. It now calls the shared helper. - Tests for both bugs in `test_dataset_aggregrations.py`. The name-collision bug predates #66194 — it dates to #20044 and survived #46668 and #50498; #66194 only lifted the loop into a helper, which is why `git blame` points there. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Aarrya <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
nadongjun
pushed a commit
to nadongjun/ray
that referenced
this pull request
Oct 6, 2026
…names (ray-project#66218) ## Why Two bugs in `TableBlockAccessor`'s aggregation path, both visible from the public API. **A global aggregation over an empty dataset returns `None`.** ```python ray.data.range(10).filter(lambda row: False).aggregate(Count()) # before: None # after: {'count()': 0} ``` ray-project#66194 added an early return for zero-row blocks. That is right for a keyed aggregation — no rows means no groups — but a global aggregation always has exactly one group, and still owes its identity row. Counting an empty dataset is `0`, not "no answer". **Repeated aggregations overwrite each other's results.** ```python ray.data.range(4).aggregate(Sum("id"), Sum("id"), Sum("id")) # before: {'sum(id)': 6, 'sum(id)_2': 6} # after: {'sum(id)': 6, 'sum(id)_2': 6, 'sum(id)_3': 6} ``` `_resolve_aggregated_column_names` suffixes duplicate names, but incremented the counter for the *suffixed* name rather than the original. The original's count never advanced past one, so every duplicate after the first resolved to `_2` again. Because `_aggregate` builds rows with `row[name] = accumulator`, two aggregations sharing a name means one result is silently dropped. ## What changes - The empty-block early return in `_aggregate` is gated on there being group keys, and the `num_rows() > 0` check around `accumulate_block` is restored, so an empty group leaves the accumulators at their identity values. - `_resolve_aggregated_column_names` counts the original name and suffixes until the name is free. Looping rather than suffixing once also covers a generated suffix colliding with an aggregation explicitly named that, as in `["a", "a_2", "a"]`. It now takes the names rather than the aggregations, since that is all it reads. - `GPUAggregationPlan` carried its own copy of that loop, which resolved names differently from the CPU path — the same query returned different column names depending on the shuffle strategy. It now calls the shared helper. - Tests for both bugs in `test_dataset_aggregrations.py`. The name-collision bug predates ray-project#66194 — it dates to ray-project#20044 and survived ray-project#46668 and ray-project#50498; ray-project#66194 only lifted the loop into a helper, which is why `git blame` points there. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Aarrya <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.
This PR adds basic support for groupby multi-aggregations.
TODOs (for future PRs)
ds.mean(["col1", "col2"])tods.aggregate(Mean("col1"), Mean("col2"))(and likewise for groupby aggregations). I've implemented a proof-of-concept for this locally, but I'm going to add it as a follow-up PR.Checks
scripts/format.shto lint the changes in this PR.