import pointblank as pb
import polars as pl
tbl = pl.DataFrame(
{
"a": [5, 7, 1, 3, 9, 4],
"b": [6, 3, 0, 5, 8, 2],
"c": [10, 4, 8, 9, 10, 5],
}
)
# Using expr_col() to create backend-agnostic validation expressions
validation = (
pb.Validate(data=tbl)
.conjointly(
lambda df: pb.expr_col("a") > 2,
lambda df: pb.expr_col("b") < 7,
lambda df: pb.expr_col("a") + pb.expr_col("b") < pb.expr_col("c")
)
.interrogate()
)
validationexpr_col()
Create a column expression for use in conjointly() validation.
Usage
expr_col(column_name)This function returns a ColumnExpression object that supports operations like >, <, +, etc. for use in conjointly() validation expressions.
Parameters
column_name: str- The name of the column to reference.
Returns
ColumnExpression- A column expression that can be used in comparisons and operations.
Examples
Let’s say we have a table with three columns: a, b, and c. We want to validate that:
- The values in column
aare greater than2. - The values in column
bare less than7. - The sum of columns
aandbis less than the values in columnc.
We can use the expr_col() function to create a column expression for each of these conditions.
The above code creates a validation object that checks the specified conditions using the expr_col() function. The resulting validation table will show whether each condition was satisfied for each row in the table.