Skip to content

Check if elements are NaN

Description

Floating point NaN (Not A Number) should not be confused with missing data represented as NA (in R) or null (in Polars).

Usage

<Expr>$is_nan()

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(
  a = c(1, 2, NA, 1, 5),
  b = c(1, 2, NaN, 1, 5)
)
df$with_columns(
  a_nan = pl$col("a")$is_nan(),
  b_nan = pl$col("b")$is_nan()
)
#> shape: (5, 4)
#> ┌──────┬─────┬───────┬───────┐
#> │ a    ┆ b   ┆ a_nan ┆ b_nan │
#> │ ---  ┆ --- ┆ ---   ┆ ---   │
#> │ f64  ┆ f64 ┆ bool  ┆ bool  │
#> ╞══════╪═════╪═══════╪═══════╡
#> │ 1.0  ┆ 1.0 ┆ false ┆ false │
#> │ 2.0  ┆ 2.0 ┆ false ┆ false │
#> │ null ┆ NaN ┆ null  ┆ true  │
#> │ 1.0  ┆ 1.0 ┆ false ┆ false │
#> │ 5.0  ┆ 5.0 ┆ false ┆ false │
#> └──────┴─────┴───────┴───────┘