Skip to content

daft.functions.repeat#

repeat #

repeat(expr: Expression, n: int | Expression) -> Expression

Repeats each string n times.

Returns:

Name Type Description
Expression Expression

a String expression which is self repeated n times

Examples:

1
2
3
4
5
>>> import daft
>>> from daft.functions import repeat
>>> df = daft.from_pydict({"x": ["daft", "query", "engine"]})
>>> df = df.select(repeat(df["x"], 5))
>>> df.show()
╭────────────────────────────────╮
│ x                              │
│ ---                            │
│ String                         │
╞════════════════════════════════╡
│ daftdaftdaftdaftdaft           │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ queryqueryqueryqueryquery      │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ engineengineengineengineengin… │
╰────────────────────────────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/str.py
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
def repeat(expr: Expression, n: int | Expression) -> Expression:
    """Repeats each string n times.

    Returns:
        Expression: a String expression which is `self` repeated `n` times

    Examples:
        >>> import daft
        >>> from daft.functions import repeat
        >>> df = daft.from_pydict({"x": ["daft", "query", "engine"]})
        >>> df = df.select(repeat(df["x"], 5))
        >>> df.show()
        ╭────────────────────────────────╮
        │ x                              │
        │ ---                            │
        │ String                         │
        ╞════════════════════════════════╡
        │ daftdaftdaftdaftdaft           │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
        │ queryqueryqueryqueryquery      │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
        │ engineengineengineengineengin… │
        ╰────────────────────────────────╯
        <BLANKLINE>
        (Showing first 3 of 3 rows)

    """
    return Expression._call_builtin_scalar_fn("repeat", expr, n)