Skip to content

daft.functions.fill_null#

fill_null #

fill_null(expr: Expression, fill_value: Expression) -> Expression

Fills null values in the Expression with the provided fill_value.

Returns:

Name Type Description
Expression Expression

Expression with null values filled with the provided fill_value

Examples:

1
2
3
4
5
6
>>> import daft
>>> from daft.functions import fill_null
>>>
>>> df = daft.from_pydict({"data": [1, None, 3]})
>>> df = df.select(fill_null(df["data"], 2))
>>> df.collect()
╭───────╮
│ data  │
│ ---   │
│ Int64 │
╞═══════╡
│ 1     │
├╌╌╌╌╌╌╌┤
│ 2     │
├╌╌╌╌╌╌╌┤
│ 3     │
╰───────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/misc.py
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
def fill_null(expr: Expression, fill_value: Expression) -> Expression:
    """Fills null values in the Expression with the provided fill_value.

    Returns:
        Expression: Expression with null values filled with the provided fill_value

    Examples:
        >>> import daft
        >>> from daft.functions import fill_null
        >>>
        >>> df = daft.from_pydict({"data": [1, None, 3]})
        >>> df = df.select(fill_null(df["data"], 2))
        >>> df.collect()
        ╭───────╮
        │ data  │
        │ ---   │
        │ Int64 │
        ╞═══════╡
        │ 1     │
        ├╌╌╌╌╌╌╌┤
        │ 2     │
        ├╌╌╌╌╌╌╌┤
        │ 3     │
        ╰───────╯
        <BLANKLINE>
        (Showing first 3 of 3 rows)

    """
    expr = Expression._to_expression(expr)
    fill_value = Expression._to_expression(fill_value)
    return Expression._from_pyexpr(expr._expr.fill_null(fill_value._expr))