Skip to content

Check if sub-arrays contain the given item

Source code

Description

Check if sub-arrays contain the given item

Usage

<Expr>$arr$contains(item, ..., nulls_equal = TRUE)

Arguments

item Item that will be checked for membership. Can be an Expr or something coercible to an Expr. Strings are not parsed as columns.
… These dots are for future extensions and must be empty.
nulls_equal If TRUE, treat null as a distinct value. Null values will not propagate.

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(
  values = list(0:2, 4:6, c(NA, NA, NA)),
  item = c(0L, 4L, 2L),
)$cast(values = pl$Array(pl$Float64, 3))
df$with_columns(
  with_expr = pl$col("values")$arr$contains(pl$col("item")$cast(pl$Float64)),
  with_lit = pl$col("values")$arr$contains(pl$lit(1)$cast(pl$Float64))
)
#> shape: (3, 4)
#> ┌────────────────────┬──────┬───────────┬──────────┐
#> │ values             ┆ item ┆ with_expr ┆ with_lit │
#> │ ---                ┆ ---  ┆ ---       ┆ ---      │
#> │ array[f64, 3]      ┆ i32  ┆ bool      ┆ bool     │
#> ╞════════════════════╪══════╪═══════════╪══════════╡
#> │ [0.0, 1.0, 2.0]    ┆ 0    ┆ true      ┆ true     │
#> │ [4.0, 5.0, 6.0]    ┆ 4    ┆ true      ┆ false    │
#> │ [null, null, null] ┆ 2    ┆ false     ┆ false    │
#> └────────────────────┴──────┴───────────┴──────────┘