Skip to content

daft.functions.list_append#

list_append #

list_append(list_expr: Expression, other: Expression) -> Expression

Appends a value to each list in the column.

Parameters:

Name Type Description Default
list_expr List Expression

expression to append to

required
other Expression

A value or column of values to append to each list

required

Returns:

Name Type Description
Expression List Expression

an expression with the updated lists

Examples:

1
2
3
4
5
>>> import daft
>>> from daft.functions import list_append
>>>
>>> df = daft.from_pydict({"a": [[1, 2], [3, 4, 5]], "b": [10, 11]})
>>> df.with_column("combined", list_append(df["a"], df["b"])).show()
╭─────────────┬───────┬───────────────╮
│ a           ┆ b     ┆ combined      │
│ ---         ┆ ---   ┆ ---           │
│ List[Int64] ┆ Int64 ┆ List[Int64]   │
╞═════════════╪═══════╪═══════════════╡
│ [1, 2]      ┆ 10    ┆ [1, 2, 10]    │
├╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ [3, 4, 5]   ┆ 11    ┆ [3, 4, 5, 11] │
╰─────────────┴───────┴───────────────╯
(Showing first 2 of 2 rows)
Source code in daft/functions/list.py
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
def list_append(list_expr: Expression, other: Expression) -> Expression:
    """Appends a value to each list in the column.

    Args:
        list_expr (List Expression): expression to append to
        other (Expression): A value or column of values to append to each list

    Returns:
        Expression (List Expression): an expression with the updated lists

    Examples:
        >>> import daft
        >>> from daft.functions import list_append
        >>>
        >>> df = daft.from_pydict({"a": [[1, 2], [3, 4, 5]], "b": [10, 11]})
        >>> df.with_column("combined", list_append(df["a"], df["b"])).show()
        ╭─────────────┬───────┬───────────────╮
        │ a           ┆ b     ┆ combined      │
        │ ---         ┆ ---   ┆ ---           │
        │ List[Int64] ┆ Int64 ┆ List[Int64]   │
        ╞═════════════╪═══════╪═══════════════╡
        │ [1, 2]      ┆ 10    ┆ [1, 2, 10]    │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
        │ [3, 4, 5]   ┆ 11    ┆ [3, 4, 5, 11] │
        ╰─────────────┴───────┴───────────────╯
        <BLANKLINE>
        (Showing first 2 of 2 rows)
    """
    return Expression._call_builtin_scalar_fn("list_append", list_expr, other)