Left-pads each string by truncating on the right or padding with the character.
Returns:
| Name | Type | Description |
Expression | Expression | a String expression which is self truncated or left-padded with the pad character |
Note
If the string is longer than the specified length, it will be truncated on the right. The pad character must be a single character.
Examples:
| >>> import daft
>>> from daft.functions import lpad
>>> df = daft.from_pydict({"x": ["daft", "query", "engine"]})
>>> df = df.select(lpad(df["x"], 6, "0"))
>>> df.show()
|
╭────────╮
│ x │
│ --- │
│ String │
╞════════╡
│ 00daft │
├╌╌╌╌╌╌╌╌┤
│ 0query │
├╌╌╌╌╌╌╌╌┤
│ engine │
╰────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/str.py
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698 | def lpad(expr: Expression, length: int | Expression, pad: str | Expression) -> Expression:
"""Left-pads each string by truncating on the right or padding with the character.
Returns:
Expression: a String expression which is `self` truncated or left-padded with the pad character
Note:
If the string is longer than the specified length, it will be truncated on the right.
The pad character must be a single character.
Examples:
>>> import daft
>>> from daft.functions import lpad
>>> df = daft.from_pydict({"x": ["daft", "query", "engine"]})
>>> df = df.select(lpad(df["x"], 6, "0"))
>>> df.show()
╭────────╮
│ x │
│ --- │
│ String │
╞════════╡
│ 00daft │
├╌╌╌╌╌╌╌╌┤
│ 0query │
├╌╌╌╌╌╌╌╌┤
│ engine │
╰────────╯
<BLANKLINE>
(Showing first 3 of 3 rows)
"""
return Expression._call_builtin_scalar_fn("lpad", expr, length, pad)
|