Validate.col_vals_gt

Validate.col_vals_gt(
    columns,
    value,
    na_pass=False,
    pre=None,
    thresholds=None,
    active=True,
)

Are column data greater than a fixed value or data in another column?

The col_vals_gt() validation method checks whether column values in a table are greater than a specified value= (the exact comparison used in this function is col_val > value). The value= can be specified as a single, literal value or as a column name given in col(). This validation will operate over the number of test units that is equal to the number of rows in the table (determined after any pre= mutation has been applied).

Parameters

columns : str | list[str]

A single column or a list of columns to validate. If multiple columns are supplied, there will be a separate validation step generated for each column.

value : float | int

The value to compare against. This can be a single numeric value or a column name given in col().

na_pass : bool = False

Should any encountered None, NA, or Null values be considered as passing test units? By default, this is False. Set to True to pass test units with missing values.

pre : Callable | None = None

A pre-processing function or lambda to apply to the data table for the validation step.

thresholds : int | float | bool | tuple | dict | Thresholds = None

Failure threshold levels so that the validation step can react accordingly when exceeding the set levels for different states (warn, stop, and notify). This can be created simply as an integer or float denoting the absolute number or fraction of failing test units for the ‘warn’ level. Otherwise, you can use a tuple of 1-3 values, a dictionary of 1-3 entries, or a Thresholds object.

active : bool = True

A boolean value indicating whether the validation step should be active. Using False will make the validation step inactive (still reporting its presence and keeping indexes for the steps unchanged).

Returns

: Validate

The Validate object with the added validation step.

Examples

For the examples here, we’ll use a simple Polars DataFrame with three numeric columns (a, b, and c). The table is shown below:

import polars as pl

tbl = pl.DataFrame(
    {
        "a": [5, 6, 5, 7, 6, 5],
        "b": [1, 2, 1, 2, 2, 2],
        "c": [2, 1, 2, 2, 3, 4],
    }
)

tbl
shape: (6, 3)
abc
i64i64i64
512
621
512
722
623
524

Let’s validate that values in column a are all greater than the value of 4. We’ll determine if this validation had any failing test units (there are six test units, one for each row).

import pointblank as pb

validation = (
    pb.Validate(data=tbl)
    .col_vals_gt(columns="a", value=4)
    .interrogate()
)

validation
Pointblank Validation
2024-12-20|15:08:47
Polars
STEP COLUMNS VALUES TBL EVAL UNITS PASS FAIL W S N EXT
#4CA64C 1
col_vals_gt
col_vals_gt()
a 4 6 6
1.00
0
0.00
2024-12-20 15:08:47 UTC< 1 s2024-12-20 15:08:47 UTC

Printing the validation object shows the validation table in an HTML viewing environment. The validation table shows the single entry that corresponds to the validation step created by using col_vals_gt(). All test units passed, and there are no failing test units.

Aside from checking a column against a literal value, we can also use a column name in the value= argument (with the helper function col()) to perform a column-column comparison. For the next example, we’ll use col_vals_gt() to check whether the values in column c are greater than values in column b.

validation = (
    pb.Validate(data=tbl)
    .col_vals_gt(columns="c", value=pb.col("b"))
    .interrogate()
)

validation
Pointblank Validation
2024-12-20|15:08:47
Polars
STEP COLUMNS VALUES TBL EVAL UNITS PASS FAIL W S N EXT
#4CA64C66 1
col_vals_gt
col_vals_gt()
c b 6 4
0.67
2
0.33
2024-12-20 15:08:47 UTC< 1 s2024-12-20 15:08:47 UTC

The validation table reports two failing test units. The specific failing cases are:

  • Row 1: c is 1 and b is 2.
  • Row 3: c is 2 and b is 2.