Skip to content

[FEA] Support ordered first/last grouped reductions in cuDF-Polars #23592

Description

@rjzamora

cudf-polars does not currently support grouped reductions where the selected value is ordered by another expression, such as pl.col("x").sort_by("t").first() inside group_by(...).agg(...).

This issue should cover the common ordered first/last grouped-reduction variants:

  • sort_by(...).first()
  • sort_by(...).last()
  • multi-key sort_by
  • descending/null-order semantics

Example:

def test_group_by_sort_by_first_last(engine: GPUEngine) -> None:
    """``group_by(...).agg(col.sort_by(...).first/last())``.

    Status
    ------
    - In-memory NOT supported
    - Streaming NOT supported
    """
    lf = pl.LazyFrame(
        {
            "g": ["A", "A", "B", "B"],
            "t": [2, 1, 2, 1],
            "x": [10, 20, 30, 40],
        }
    )

    q = lf.group_by("g").agg(
        first_x=pl.col("x").sort_by("t").first(),
        last_x=pl.col("x").sort_by("t").last(),
    )
    assert_gpu_result_equal(q, engine=engine)

Metadata

Metadata

Assignees

No one assigned

    Labels

    cudf-polarsIssues specific to cudf-polarsfeature requestNew feature or request

    Type

    No type

    Projects

    Status
    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions