Skip to content

daft.functions.chr_func#

chr_func #

chr_func(expr: Expression) -> Expression

Converts an ASCII numeric value to a character.

Returns the character corresponding to the ASCII code. This is compatible with Spark's chr function.

Parameters:

Name Type Description Default
expr Expression

An integer expression representing the ASCII code

required

Returns:

Name Type Description
Expression Expression

a String expression with the character

Examples:

1
2
3
4
5
>>> import daft
>>> from daft.functions import chr_func
>>> df = daft.from_pydict({"x": [65, 97, 48]})
>>> df = df.select(chr_func(df["x"]))
>>> df.show()
╭────────╮
│ x      │
│ ---    │
│ String │
╞════════╡
│ A      │
├╌╌╌╌╌╌╌╌┤
│ a      │
├╌╌╌╌╌╌╌╌┤
│ 0      │
╰────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/str.py
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
def chr_func(expr: Expression) -> Expression:
    """Converts an ASCII numeric value to a character.

    Returns the character corresponding to the ASCII code.
    This is compatible with Spark's chr function.

    Args:
        expr: An integer expression representing the ASCII code

    Returns:
        Expression: a String expression with the character

    Examples:
        >>> import daft
        >>> from daft.functions import chr_func
        >>> df = daft.from_pydict({"x": [65, 97, 48]})
        >>> df = df.select(chr_func(df["x"]))
        >>> df.show()
        ╭────────╮
        │ x      │
        │ ---    │
        │ String │
        ╞════════╡
        │ A      │
        ├╌╌╌╌╌╌╌╌┤
        │ a      │
        ├╌╌╌╌╌╌╌╌┤
        │ 0      │
        ╰────────╯
        <BLANKLINE>
        (Showing first 3 of 3 rows)

    """
    return Expression._call_builtin_scalar_fn("chr", expr)