admin管理员组

文章数量:1303428

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.

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.

Share Improve this question edited Feb 10 at 17:52 jqurious 21.6k4 gold badges20 silver badges39 bronze badges asked Feb 10 at 17:36 Gregg LindGregg Lind 21.3k15 gold badges69 silver badges81 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 5

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.

本文标签: pythonDefault filter expression to quotmatch anythingquotStack Overflow