Skip to content

daft.functions.left#

left #

left(expr: Expression, nchars: int | Expression) -> Expression

Gets the n (from nchars) left-most characters of each string.

Returns:

Name Type Description
Expression Expression

a String expression which is the n left-most characters of self

Examples:

1
2
3
4
5
>>> import daft
>>> from daft.functions import left
>>> df = daft.from_pydict({"x": ["daft", "query", "engine"]})
>>> df = df.select(left(df["x"], 4))
>>> df.show()
╭────────╮
│ x      │
│ ---    │
│ String │
╞════════╡
│ daft   │
├╌╌╌╌╌╌╌╌┤
│ quer   │
├╌╌╌╌╌╌╌╌┤
│ engi   │
╰────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/str.py
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
def left(expr: Expression, nchars: int | Expression) -> Expression:
    """Gets the n (from nchars) left-most characters of each string.

    Returns:
        Expression: a String expression which is the `n` left-most characters of `self`

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

    """
    return Expression._call_builtin_scalar_fn("left", expr, nchars)