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
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
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)