Validate.col_vals_in_set

Validate.col_vals_in_set(
    columns,
    set,
    pre=None,
    thresholds=None,
    actions=None,
    brief=None,
    active=True,
)

Validate whether column values are in a set of values.

The col_vals_in_set() validation method checks whether column values in a table are part of a specified set= of values. 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] | Column | ColumnSelector | ColumnSelectorNarwhals

A single column or a list of columns to validate. Can also use col() with column selectors to specify one or more columns. If multiple columns are supplied or resolved, there will be a separate validation step generated for each column.

set : list[float | int]

A list of values to compare against.

pre : Callable | None = None

A optional preprocessing function or lambda to apply to the data table during interrogation.

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

Optional failure threshold levels for the validation step(s), so that the interrogation can react accordingly when exceeding the set levels for different states (‘warning’, ‘error’, and ‘critical’). This can be created using the Thresholds class or more simply as (1) an integer or float denoting the absolute number or fraction of failing test units for the ‘warn’ level, (2) a tuple of 1-3 values, or (3) a dictionary of 1-3 entries.

actions : Actions | None = None

Optional actions to take when the validation step(s) meets or exceeds any set threshold levels. If provided, the Actions class should be used to define the actions.

brief : str | None = None

An optional brief description of the validation step. The templating elements "{col}" and "{step}" can be used to insert the column name and step number, respectively.

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 two numeric columns (a and b). The table is shown below:

import pointblank as pb
import polars as pl

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

pb.preview(tbl)
a
Int64
b
Int64
1 5 5
2 2 8
3 4 2
4 6 6
5 2 5
6 5 1

Let’s validate that values in column a are all in the set of [2, 3, 4, 5, 6]. We’ll determine if this validation had any failing test units (there are six test units, one for each row).

validation = (
    pb.Validate(data=tbl)
    .col_vals_in_set(columns="a", set=[2, 3, 4, 5, 6])
    .interrogate()
)

validation
STEP COLUMNS VALUES TBL EVAL UNITS PASS FAIL W E C EXT
#4CA64C 1
col_vals_in_set
col_vals_in_set()
a 2, 3, 4, 5, 6 6 6
1.00
0
0.00

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_in_set(). All test units passed, and there are no failing test units.

Now, let’s use that same set of values for a validation on column b.

validation = (
    pb.Validate(data=tbl)
    .col_vals_in_set(columns="b", set=[2, 3, 4, 5, 6])
    .interrogate()
)

validation
STEP COLUMNS VALUES TBL EVAL UNITS PASS FAIL W E C EXT
#4CA64C66 1
col_vals_in_set
col_vals_in_set()
b 2, 3, 4, 5, 6 6 4
0.67
2
0.33

The validation table reports two failing test units. The specific failing cases are for the column b values of 8 and 1, which are not in the set of [2, 3, 4, 5, 6].