ray.data.aggregate.AsList#

class ray.data.aggregate.AsList(on: str, alias_name: str | None = None, ignore_nulls: bool = False)[source]#

Bases: AggregateFnV2[List, List]

Listing aggregation combining all values within the group into a single list element.

Example

# Skip testing b/c this example require proper ordering of the output
# to be robust and not flaky

import ray
from ray.data.aggregate import AsList

ds = ray.data.range(10)
# Schema: {'id': int64}
ds = ds.add_column("group_key", lambda x: x % 3)
# Schema: {'id': int64, 'group_key': int64}

# Listing all elements per group:
result = ds.groupby("group_key").aggregate(AsList(on="id")).take_all()
# result: [{'group_key': 0, 'list(id)': [0, 3, 6, 9]},
#          {'group_key': 1, 'list(id)': [1, 4, 7]},
#          {'group_key': 2, 'list(id)': [2, 5, 8]}
Parameters:
  • on – The name of the column to collect values from. Must be provided.

  • alias_name – Optional name for the resulting column.

  • ignore_nulls – Whether to ignore null values when collecting. If True, nulls are skipped. If False (default), nulls are included in the list.

Methods

finalize

Transforms the final accumulated state into the desired output.

get_agg_name

Return the agg name (e.g., 'sum', 'mean', 'count').