Sum#
- class ray.data.aggregate.Sum(on: str | None = None, ignore_nulls: bool = True, alias_name: str | None = None)[source]#
Bases:
VectorizedAggregateFnV2[int|float,int|float]Defines sum aggregation.
Examples
>>> import ray >>> from ray.data.aggregate import Sum >>> ds = ray.data.range(100) >>> # Schema: {'id': int64} >>> ds = ds.add_column( ... "group_key", lambda batch: batch["id"].astype("int64") % 3 ... ) >>> # Schema: {'id': int64, 'group_key': int64} >>> # Summing all rows per group: >>> result = ds.aggregate(Sum(on="id")) >>> # result: {'sum(id)': 4950}
- Parameters:
on (str | None) – The name of the numerical column to sum. Must be provided.
ignore_nulls (bool) – Whether to ignore null values during summation. If
True(default), nulls are skipped. IfFalse, the sum will be null if any value in the group is null.alias_name (str | None) – Optional name for the resulting column.
Methods
Transforms the final accumulated state into the desired output.
Return the agg name (e.g., 'sum', 'mean', 'count').
Return the name of the column this aggregation reads.