polars.Expr.any#

Expr.any(drop_nulls: bool = True) Self[source]#

Check if any boolean value in a Boolean column is True.

Parameters:
drop_nulls

If False, return None if there are nulls but no Trues.

Returns:
Expr

Expression of data type Boolean.

Examples

>>> df = pl.DataFrame({"TF": [True, False], "FF": [False, False]})
>>> df.select(pl.all().any())
shape: (1, 2)
┌──────┬───────┐
│ TF   ┆ FF    │
│ ---  ┆ ---   │
│ bool ┆ bool  │
╞══════╪═══════╡
│ true ┆ false │
└──────┴───────┘
>>> df = pl.DataFrame(dict(x=[None, False], y=[None, True]))
>>> df.select(pl.col("x").any(True), pl.col("y").any(True))
shape: (1, 2)
┌───────┬──────┐
│ x     ┆ y    │
│ ---   ┆ ---  │
│ bool  ┆ bool │
╞═══════╪══════╡
│ false ┆ true │
└───────┴──────┘
>>> df.select(pl.col("x").any(False), pl.col("y").any(False))
shape: (1, 2)
┌──────┬──────┐
│ x    ┆ y    │
│ ---  ┆ ---  │
│ bool ┆ bool │
╞══════╪══════╡
│ null ┆ true │
└──────┴──────┘