import pointblank as pb
import os
import tempfile
validation = (
pb.Validate(data=pb.load_dataset("small_table"), tbl_name="small_table")
.col_vals_gt(columns="d", value=1000)
.col_vals_not_null(columns="c")
.interrogate()
)
save_dir = tempfile.mkdtemp()
pb.write_file(validation, "my_validation", path=save_dir, keep_tbl=True, quiet=True)read_file()
Read a Validate object from disk that was previously saved with write_file().
Usage
read_file(filepath)This function loads a validation object that was previously serialized to disk using the write_file() function. The validation object will be restored with all its validation results, metadata, and optionally the source data (if it was saved with keep_tbl=True).
The read_file() function is currently experimental. Please report any issues you encounter in the Pointblank issue tracker.
Parameters
filepath: str | Path- The path to the saved validation file. Can be a string or Path object.
Returns
Validate- The restored validation object with all its original state, validation results, and metadata.
Examples
Let’s first save a validation object to disk with write_file(). We’ll use a temporary directory here, and keep_tbl=True saves the target table along with the validation results:
Now we can load the validation object from disk with read_file(). The filename can be given without its extension, in which case read_file() looks for "my_validation.pkl":
restored = pb.read_file(os.path.join(save_dir, "my_validation"))
restored| STEP | COLUMNS | VALUES | TBL | EVAL | UNITS | PASS | FAIL | W | E | C | EXT | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| #4CA64C66 | 1 |
col_vals_gt()
|
✓ | 13 | 7 0.54 |
6 0.46 |
— | — | — | — | |||
| #4CA64C66 | 2 |
col_vals_not_null()
|
✓ | 13 | 11 0.85 |
2 0.15 |
— | — | — | — |
The restored object has the same results as the original: the first step has 6 failing test units and the second has 2. The loaded validation object retains all its functionality, so we can, for example, get the rows that failed any step (since the target table was saved):
pb.preview(restored.get_sundered_data(type="fail"))PolarsRows8Columns8 |
||||||||
These are the 8 rows of small_table that failed at least one of the two steps. Without keep_tbl=True in write_file(), the table wouldn’t be saved and methods that need the data, like get_sundered_data(), wouldn’t be available after loading.
See Also
- write_file()
-
Save a validation object to disk for later retrieval with read_file().