Skip to content

daft.functions.startswith#

startswith #

startswith(expr: Expression, prefix: str | Expression) -> Expression

Checks whether each string starts with the given prefix in a string column.

Parameters:

Name Type Description Default
expr Expression

The expression to check.

required
prefix str | Expression

The prefix to search for as a literal string, or as a column to pick values from

required

Returns:

Name Type Description
Expression Expression

a Boolean expression indicating whether each value starts with the provided prefix

Examples:

1
2
3
4
>>> import daft
>>> from daft.functions import startswith
>>> df = daft.from_pydict({"x": ["geftdaft", "lazy", "daft.io"]})
>>> df.with_column("match", startswith(df["x"], "daft")).collect()
╭──────────┬───────╮
│ x        ┆ match │
│ ---      ┆ ---   │
│ String   ┆ Bool  │
╞══════════╪═══════╡
│ geftdaft ┆ false │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
│ lazy     ┆ false │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
│ daft.io  ┆ true  │
╰──────────┴───────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/str.py
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
def startswith(expr: Expression, prefix: str | Expression) -> Expression:
    """Checks whether each string starts with the given prefix in a string column.

    Args:
        expr: The expression to check.
        prefix: The prefix to search for as a literal string, or as a column to pick values from

    Returns:
        Expression: a Boolean expression indicating whether each value starts with the provided prefix

    Examples:
        >>> import daft
        >>> from daft.functions import startswith
        >>> df = daft.from_pydict({"x": ["geftdaft", "lazy", "daft.io"]})
        >>> df.with_column("match", startswith(df["x"], "daft")).collect()
        ╭──────────┬───────╮
        │ x        ┆ match │
        │ ---      ┆ ---   │
        │ String   ┆ Bool  │
        ╞══════════╪═══════╡
        │ geftdaft ┆ false │
        ├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
        │ lazy     ┆ false │
        ├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
        │ daft.io  ┆ true  │
        ╰──────────┴───────╯
        <BLANKLINE>
        (Showing first 3 of 3 rows)

    """
    return Expression._call_builtin_scalar_fn("starts_with", expr, prefix)