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 than 2.
  • The values in column b are less than 7.
  • The sum of columns a and b is less than the values in column c.

We can use the expr_col() function to create a column expression for each of these conditions.

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()
)

validation
STEP COLUMNS VALUES TBL EVAL UNITS PASS FAIL W E C EXT
#4CA64C66 1
conjointly
conjointly()
COLUMN EXPR 6 1
0.17
5
0.83

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.