import polars as pl
= pl.DataFrame(
tbl
{"a": [4, 7, 2, 8],
"b": [5, None, 1, None],
}
)
tbl
a | b |
---|---|
i64 | i64 |
4 | 5 |
7 | null |
2 | 1 |
8 | null |
Validate whether values in a column are not NULL.
The col_vals_not_null()
validation method checks whether column values in a table are not NULL. This validation will operate over the number of test units that is equal to the number of rows in the table.
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.
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).
: Validate
The Validate
object with the added validation step.
For the examples here, we’ll use a simple Polars DataFrame with two numeric columns (a
and b
). The table is shown below:
a | b |
---|---|
i64 | i64 |
4 | 5 |
7 | null |
2 | 1 |
8 | null |
Let’s validate that none of the values in column a
are Null values. We’ll determine if this validation had any failing test units (there are four test units, one for each row).
import pointblank as pb
validation = (
pb.Validate(data=tbl)
.col_vals_not_null(columns="a")
.interrogate()
)
validation
Pointblank Validation | |||||||||||||
2024-12-20|15:09:17 Polars |
|||||||||||||
STEP | COLUMNS | VALUES | TBL | EVAL | UNITS | PASS | FAIL | W | S | N | EXT | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
#4CA64C | 1 |
|
a | — | ✓ | 4 | 4 1.00 |
0 0.00 |
— | — | — | — | |
2024-12-20 15:09:17 UTC< 1 s2024-12-20 15:09:17 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_not_null()
. 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
.
The validation table reports two failing test units. The specific failing cases are for the two Null values in column b
.