Skip to content

daft.functions.fill_nan#

fill_nan #

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

Fills NaN values in the Expression with the provided fill_value.

Returns:

Name Type Description
Expression Expression

Expression with Nan values filled with the provided fill_value

Examples:

1
2
3
4
5
6
>>> import daft
>>> from daft.functions import fill_nan
>>>
>>> df = daft.from_pydict({"data": [1.1, float("nan"), 3.3]})
>>> df = df.with_column("filled", fill_nan(df["data"], 2.2))
>>> df.show()
╭─────────┬─────────╮
│ data    ┆ filled  │
│ ---     ┆ ---     │
│ Float64 ┆ Float64 │
╞═════════╪═════════╡
│ 1.1     ┆ 1.1     │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ NaN     ┆ 2.2     │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ 3.3     ┆ 3.3     │
╰─────────┴─────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/numeric.py
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
def fill_nan(expr: Expression, fill_value: Expression) -> Expression:
    """Fills NaN values in the Expression with the provided fill_value.

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

    Examples:
        >>> import daft
        >>> from daft.functions import fill_nan
        >>>
        >>> df = daft.from_pydict({"data": [1.1, float("nan"), 3.3]})
        >>> df = df.with_column("filled", fill_nan(df["data"], 2.2))
        >>> df.show()
        ╭─────────┬─────────╮
        │ data    ┆ filled  │
        │ ---     ┆ ---     │
        │ Float64 ┆ Float64 │
        ╞═════════╪═════════╡
        │ 1.1     ┆ 1.1     │
        ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
        │ NaN     ┆ 2.2     │
        ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
        │ 3.3     ┆ 3.3     │
        ╰─────────┴─────────╯
        <BLANKLINE>
        (Showing first 3 of 3 rows)

    """
    return Expression._call_builtin_scalar_fn("fill_nan", expr, fill_value)