polars
PolarsPredicate(expr)
Bases: Predicate
Predicate for Polars DataFrame.
This predicate allows for two different ways to provide the predicate expression:
-
As a Polars expression. This expression is used directly and must evaluate to a single boolean value. For example, the following expression checks if the values in the "feature_a" column are in the list [1, 2, 3] and if the values in the "feature_b" column are greater than 0:
import polars as pl PolarsPredicate( pl.col("feature_a").is_in([1, 2, 3]).and_(pl.col("feature_b") > 0), )
-
As a string. The string is parsed as a Polars expression. Any string identifier are replace with the respective feature during evaluation. The string expression must evaluate to a single boolean value as well. For example, the following expression checks if "feature_a" is always greater than "feature_b":
Boolean expressions likeimport polars as pl PolarsPredicate( "feature_a > feature_b", )
and
,or
, andnot
are not supported by this syntax. SeeAndPredicate
,OrPredicate
andNotPredicate
for combined predicates or use the polars expression syntax above.
Initialize the predicate from a polars expression or a string.
Source code in src/flowcean/core/tool/testing/predicates/polars.py
44 45 46 |
|