[go: up one dir, main page]

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
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
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)