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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
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)