Skip to content

daft.functions.space#

space #

space(expr: Expression) -> Expression

Returns a string consisting of n space characters.

This is compatible with Spark's space function.

Parameters:

Name Type Description Default
expr Expression

An integer expression representing the number of spaces

required

Returns:

Name Type Description
Expression Expression

a String expression with n spaces

Examples:

1
2
3
4
5
>>> import daft
>>> from daft.functions import space
>>> df = daft.from_pydict({"x": [1, 3, 5]})
>>> df = df.select(space(df["x"]))
>>> df.show()
╭────────╮
│ x      │
│ ---    │
│ String │
╞════════╡
│        │
├╌╌╌╌╌╌╌╌┤
│        │
├╌╌╌╌╌╌╌╌┤
│        │
╰────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/str.py
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
def space(expr: Expression) -> Expression:
    """Returns a string consisting of n space characters.

    This is compatible with Spark's space function.

    Args:
        expr: An integer expression representing the number of spaces

    Returns:
        Expression: a String expression with n spaces

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

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