Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default filter expression to "match anything"

What kind of polars expression (pl.Expr) might be used in a filter context that will match anything including nulls?

Use case: Type hinting and helper Functions that should return an polars.Expr.

like image 594
Gregg Lind Avatar asked Nov 03 '25 08:11

Gregg Lind


1 Answers

The expression representing the literal value True might be used. See pl.lit for more details.

Example.

import polars as pl

df = pl.DataFrame({
    "a": [1, 2, None]
})

df.filter(pl.lit(True))
shape: (3, 1)
┌──────┐
│ a    │
│ ---  │
│ i64  │
╞══════╡
│ 1    │
│ 2    │
│ null │
└──────┘

Note. In general, simply True also works, but its not an instance of pl.Expr.

like image 79
Hericks Avatar answered Nov 04 '25 23:11

Hericks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!