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
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833 | 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)
|