import pointblank as pb
import polars as pl
# Create two similar tables
= pl.DataFrame({
table_1 "x": [1, 2, 3, 4, 5],
"y": [5, 4, 3, 2, 1],
"z": ["a", "b", "c", "d", "e"]
})
= pl.DataFrame({
table_2 "x": [2, 4, 6, 8, 10],
"y": [10, 8, 6, 4, 2],
"z": ["f", "g", "h", "i", "j"]
})
set_tbl()method
Set or replace the table associated with the Validate object.
USAGE
=None, label=None) Validate.set_tbl(tbl, tbl_name
This method allows you to replace the table associated with a Validate object with a different (but presumably similar) table. This is useful when you want to apply the same validation plan to multiple tables or when you have a validation workflow defined but want to swap in a different data source.
Parameters
tbl :
FrameT
|Any
-
The table to replace the existing table with. This can be any supported table type including DataFrame objects, Ibis table objects, CSV file paths, Parquet file paths, GitHub URLs, or database connection strings. The same table type constraints apply as in the
Validate
constructor. tbl_name :
str
| None = None-
An optional name to assign to the new input table object. If no value is provided, the existing table name will be retained.
label :
str
| None = None-
An optional label for the validation plan. If no value is provided, the existing label will be retained.
Returns
When to Use
The set_tbl()
method is particularly useful in scenarios where you have:
- multiple similar tables that need the same validation checks
- a template validation workflow that should be applied to different data sources
- YAML-defined validations where you want to override the table specified in the YAML
The set_tbl()
method creates a copy of the validation object with the new table, so the original validation object remains unchanged. This allows you to reuse validation plans across multiple tables without interference.
Examples
We will first create two similar tables for our future validation plans.
Create a validation plan with the first table.
= (
validation_table_1
pb.Validate(=table_1,
data="Table 1",
tbl_name="Validation applied to the first table"
label
)="x", value=0)
.col_vals_gt(columns="y", value=10)
.col_vals_lt(columns )
Now apply the same validation plan to the second table.
= (
validation_table_2
validation_table_1
.set_tbl(=table_2,
tbl="Table 2",
tbl_name="Validation applied to the second table"
label
) )
Here is the interrogation of the first table:
validation_table_1.interrogate()
STEP | COLUMNS | VALUES | TBL | EVAL | UNITS | PASS | FAIL | W | E | C | EXT | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
#4CA64C | 1 |
col_vals_gt()
|
✓ | 5 | 5 1.00 |
0 0.00 |
— | — | — | — | |||
#4CA64C | 2 |
col_vals_lt()
|
✓ | 5 | 5 1.00 |
0 0.00 |
— | — | — | — |
And the second table: