Skip to content

Apply logical AND on a column

Source code

Description

Check if all values in a Boolean column are TRUE. This method is an expression - not to be confused with pl$all() which is a function to select all columns.

Usage

<Expr>$all(..., ignore_nulls = TRUE)

Arguments

Ignored.
ignore_nulls If TRUE (default), ignore null values. If FALSE, Kleene logic is used to deal with nulls: if the column contains any null values and no TRUE values, the output is null.

Value

A logical value

Examples

library(polars)

df = pl$DataFrame(
  a = c(TRUE, TRUE),
  b = c(TRUE, FALSE),
  c = c(NA, TRUE),
  d = c(NA, NA)
)

# By default, ignore null values. If there are only nulls, then all() returns
# TRUE.
df$select(pl$col("*")$all())
#> shape: (1, 4)
#> ┌──────┬───────┬──────┬──────┐
#> │ a    ┆ b     ┆ c    ┆ d    │
#> │ ---  ┆ ---   ┆ ---  ┆ ---  │
#> │ bool ┆ bool  ┆ bool ┆ bool │
#> ╞══════╪═══════╪══════╪══════╡
#> │ true ┆ false ┆ true ┆ true │
#> └──────┴───────┴──────┴──────┘
# If we set ignore_nulls = FALSE, then we don't know if all values in column
# "c" are TRUE, so it returns null
df$select(pl$col("*")$all(ignore_nulls = FALSE))
#> shape: (1, 4)
#> ┌──────┬───────┬──────┬──────┐
#> │ a    ┆ b     ┆ c    ┆ d    │
#> │ ---  ┆ ---   ┆ ---  ┆ ---  │
#> │ bool ┆ bool  ┆ bool ┆ bool │
#> ╞══════╪═══════╪══════╪══════╡
#> │ true ┆ false ┆ null ┆ null │
#> └──────┴───────┴──────┴──────┘