Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Polars · Function

pl.any

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.

How it works

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.

Syntax

Expr.any(*, ignore_nulls: bool = True) → Expr

Parameters

NameTypeDescription
ignore_nullsboolControls whether null values are ignored. Defaults to True; False enables Kleene logic.

Returns

An Expr with Boolean data type.

Key points

  • The method performs a column-wise existence check for true values.
  • The default setting makes null entries irrelevant to the aggregation.
  • Passing False changes null handling to three-valued Kleene logic.
  • The resulting expression has Boolean data type.
  • Use the keyword argument to explicitly request null-aware logical behavior.

Common mistakes

  • The expression is restricted to Boolean columns; applying it to another data type is unsupported.
  • With the default null-ignoring behavior, an entirely null column reduces to False.
  • When ignore_nulls=False, a null result is possible if the column has nulls but no true values.

Example: Check whether columns contain any true values

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.

When to use it

Column-level Boolean summaries

Summarize flag columns in a DataFrame by checking whether each column has any true entry.

Null-aware aggregation

Preserve uncertainty when missing Boolean values matter to downstream logic.

Expression-based feature checks

Use inside select or other expression contexts to create Boolean aggregate outputs.

Interview questions

QWhat does Expr.any return?

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.

QWhat is the default null behavior?

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.

QWhen should ignore_nulls be set to False?

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_horizontal
  • polars.col

Source: polars.Expr.any — Polars documentation. Checked 2026-10-15.