Repository navigation
[Data] Abstracting common methods, removing duplication in ArrowBlockAccessor, PandasBlockAccessor - #50498
Conversation
…sor`, remove duplication Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
4940f45 to
9590834
Compare
…sed on provided key Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
|
|
||
| return _get_group_boundaries_sorted_numpy(projected_block) | ||
|
|
||
| return np.array([0, block_accessor.num_rows()]) |
There was a problem hiding this comment.
why return this when key is empty? Should we just raise an error?
There was a problem hiding this comment.
It's semantically correct -- there's just 1 group. Otherwise, i'd need to handle that case separately at every caller
| by a list of 1D numpy arrays for each column. In each column, | ||
| NaNs/None are considered to be the same group. | ||
| def _get_group_boundaries_sorted( | ||
| block: Block, key: Union[str, List[str]] |
There was a problem hiding this comment.
key: Union[str, List[str]]
not a new issue, but I think we should stop handling key-or-keys everywhere. Ideally only the user-facing API needs to deals with single or multiple keys.
All internal function should only handle lists to simplify code
There was a problem hiding this comment.
On the same page. Let me fix that
|
|
||
| # Get the list of boundaries including first start and last end indices | ||
| if key: | ||
| projected_block = block_accessor.to_numpy(key) |
There was a problem hiding this comment.
to_numpy isn't zero-copy. we should probably push down the implementation to each BlockAccessor and use their native methods.
There was a problem hiding this comment.
to_numpy will be zero-copy if it's
- Contiguous
- Numerical
- No nans/nulls
Since it's sorted it has quite good chances of being one. But even when it's not it's still gonna be way faster than what we do right now (deserializing the keys and iterating in Python)
Signed-off-by: Alexey Kudinkin <[email protected]>
92bc5ad to
03d0682
Compare
… keys Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
…-type if no target one was provided Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
…kAccessor`, `PandasBlockAccessor` (ray-project#50498) ## Why are these changes needed? Abstracting common methods, removing duplication in `ArrowBlockAccessor`, `PandasBlockAccessor`. --------- Signed-off-by: Alexey Kudinkin <[email protected]>
…kAccessor`, `PandasBlockAccessor` (ray-project#50498) ## Why are these changes needed? Abstracting common methods, removing duplication in `ArrowBlockAccessor`, `PandasBlockAccessor`. --------- Signed-off-by: Alexey Kudinkin <[email protected]>
…kAccessor`, `PandasBlockAccessor` (ray-project#50498) ## Why are these changes needed? Abstracting common methods, removing duplication in `ArrowBlockAccessor`, `PandasBlockAccessor`. --------- Signed-off-by: Alexey Kudinkin <[email protected]>
…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]>
…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]>
Why are these changes needed?
Abstracting common methods, removing duplication in
ArrowBlockAccessor,PandasBlockAccessor.Related issue number
Checks
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/under thecorresponding
.rstfile.