Skip to content

daft.functions.seq#

seq #

Generates a list of sequential integers [0, 1, 2, ..., n-1] for each row.

Parameters:

Name Type Description Default
n Expression

An integer expression specifying the length of the sequence.

required

Returns:

Name Type Description
Expression List[UInt64] Expression

An expression with lists of sequential integers.

Examples:

1
2
3
4
>>> import daft
>>> from daft.functions import seq
>>> df = daft.from_pydict({"n": [3, 5, 0]})
>>> df.with_column("indices", seq(df["n"])).collect()
╭───────┬─────────────────╮
│ n     ┆ indices         │
│ ---   ┆ ---             │
│ Int64 ┆ List[UInt64]    │
╞═══════╪═════════════════╡
│ 3     ┆ [0, 1, 2]       │
├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 5     ┆ [0, 1, 2, 3, 4] │
├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 0     ┆ []              │
╰───────┴─────────────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/list.py
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
def seq(n: Expression) -> Expression:
    """Generates a list of sequential integers [0, 1, 2, ..., n-1] for each row.

    Args:
        n (Expression): An integer expression specifying the length of the sequence.

    Returns:
        Expression (List[UInt64] Expression): An expression with lists of sequential integers.

    Examples:
        >>> import daft
        >>> from daft.functions import seq
        >>> df = daft.from_pydict({"n": [3, 5, 0]})
        >>> df.with_column("indices", seq(df["n"])).collect()
        ╭───────┬─────────────────╮
        │ n     ┆ indices         │
        │ ---   ┆ ---             │
        │ Int64 ┆ List[UInt64]    │
        ╞═══════╪═════════════════╡
        │ 3     ┆ [0, 1, 2]       │
        ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
        │ 5     ┆ [0, 1, 2, 3, 4] │
        ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
        │ 0     ┆ []              │
        ╰───────┴─────────────────╯
        <BLANKLINE>
        (Showing first 3 of 3 rows)
    """
    return Expression._call_builtin_scalar_fn("list_seq", n)