Skip to content

Check if elements are not 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_not_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_not_nan = pl$col("a")$is_not_nan(),
  b_not_nan = pl$col("b")$is_not_nan()
)
#> shape: (5, 4)
#> ┌──────┬─────┬───────────┬───────────┐
#> │ a    ┆ b   ┆ a_not_nan ┆ b_not_nan │
#> │ ---  ┆ --- ┆ ---       ┆ ---       │
#> │ f64  ┆ f64 ┆ bool      ┆ bool      │
#> ╞══════╪═════╪═══════════╪═══════════╡
#> │ 1.0  ┆ 1.0 ┆ true      ┆ true      │
#> │ 2.0  ┆ 2.0 ┆ true      ┆ true      │
#> │ null ┆ NaN ┆ null      ┆ false     │
#> │ 1.0  ┆ 1.0 ┆ true      ┆ true      │
#> │ 5.0  ┆ 5.0 ┆ true      ┆ true      │
#> └──────┴─────┴───────────┴───────────┘