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
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
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)