Column-level Boolean summaries
Summarize flag columns in a DataFrame by checking whether each column has any true entry.
Polars · Function
Reduces a Boolean column to whether it contains at least one True value. Nulls are ignored by default, or handled with Kleene logic when ignore_nulls=False.
Use this expression method on Boolean columns to reduce each column to one Boolean result. By default, nulls do not affect the result; setting ignore_nulls=False applies Kleene logic, which can produce null when no true value exists but a null is present.
Expr.any(*, ignore_nulls: bool = True) → Expr| Name | Type | Description |
|---|---|---|
ignore_nulls | bool | Controls whether null values are ignored. Defaults to True; False enables Kleene logic. |
An Expr with Boolean data type.
import polars as pl
df = pl.DataFrame({
"a": [True, False],
"b": [False, False],
"c": [None, False],
})
result = df.select(pl.col("*").any())
print(result)Aggregates each Boolean column into one value indicating whether it contains any true value.
Summarize flag columns in a DataFrame by checking whether each column has any true entry.
Preserve uncertainty when missing Boolean values matter to downstream logic.
Use inside select or other expression contexts to create Boolean aggregate outputs.
Expr.any reduces a Boolean column to an expression that reports whether at least one value is True. It returns an Expr whose data type is Boolean.
Follow-up: How does it behave with nulls? With ignore_nulls=True, nulls are skipped; with ignore_nulls=False, Kleene logic can return null.
ignore_nulls defaults to True, so null values are ignored during aggregation. If no non-null values remain, the result is False.
Follow-up: What result does an all-null column produce by default? False, because nulls are ignored and no true value is found.
Set ignore_nulls=False to enable Kleene logic. In that mode, a column containing null and no True produces null rather than False.
Follow-up: What result does [True, null] produce with Kleene logic? True, because the presence of a true value determines the logical OR result.
polars.Expr.and_polars.any_horizontalpolars.col