Skip to content

daft.functions.endswith#

endswith #

endswith(expr: Expression, suffix: str | Expression) -> Expression

Checks whether each string ends with the given suffix in a string column.

Parameters:

Name Type Description Default
expr Expression

The expression to check.

required
suffix str | Expression

The suffix 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 ends with the provided suffix

Examples:

1
2
3
4
>>> import daft
>>> from daft.functions import endswith
>>> df = daft.from_pydict({"x": ["geftdaft", "lazy", "daft.io"]})
>>> df.with_column("match", endswith(df["x"], "daft")).collect()
╭──────────┬───────╮
│ x        ┆ match │
│ ---      ┆ ---   │
│ String   ┆ Bool  │
╞══════════╪═══════╡
│ geftdaft ┆ true  │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
│ lazy     ┆ false │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
│ daft.io  ┆ false │
╰──────────┴───────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/str.py
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
def endswith(expr: Expression, suffix: str | Expression) -> Expression:
    """Checks whether each string ends with the given suffix in a string column.

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

    Returns:
        Expression: a Boolean expression indicating whether each value ends with the provided suffix

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

    """
    return Expression._call_builtin_scalar_fn("ends_with", expr, suffix)