import pointblank as pb
import polars as pl
= pl.DataFrame(
tbl
{"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 =tbl)
pb.Validate(data
.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()
)
validation
expr_col
expr_col(column_name)
Create a column expression for use in conjointly()
validation.
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
a
are greater than2
. - The values in column
b
are less than7
. - The sum of columns
a
andb
is 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.
See Also
The conjointly()
validation method, which is where this function should be used.