import pointblank as pb
import tempfile
from pathlib import Path
results = Path(tempfile.mkdtemp()) / "results"
for tbl_name in ["small_table", "game_revenue"]:
validation = (
pb.Validate(data=pb.load_dataset(dataset=tbl_name), tbl_name=tbl_name)
.row_count_match(count=2000)
.interrogate()
)
pb.write_results(validation, filename=tbl_name, path=results)MultiValidate.from_files()
Collect validations saved with write_results() or write_file().
Usage
MultiValidate.from_files(
files,
order="time",
)The from_files() method reads the results files written by write_results() (with read_results()) and the validations saved with write_file() (with read_file()), and collects them in a MultiValidate object. This is how the results of jobs that ran separately, perhaps on other machines, can be put in one report. The validations don’t need to have been saved with their tables (keep_tbl=True), since the reports and the roll-up methods only use the results.
The files of write_file() (.pkl files) are Python pickles, and reading one can run code that’s in it. Only read them if you trust them, such as those written by your own jobs. Results files (.json files) are safe to read from any source.
Parameters
files: str | Path | list[str | Path] | tuple[str | Path, …]-
The files to read. This can be a path to a file, a directory (all of its
.jsonand.pklfiles are read), a glob pattern (e.g.,"results/*.json"), or a list of paths to files. A.jsonfile is read as a results file and any other file as a file of write_file() (as in read_file(), a path without an extension gets.pkl). order: Literal["time", "given"] = "time"-
The order of the runs:
"time"(the default) orders them by the time their interrogation ended, and"given"keeps the order of the files (for a directory or a pattern, the files are sorted by name).
Returns
MultiValidate- A MultiValidate object with a run for each file.
Raises
FileNotFoundError- If a directory or a pattern matches no files.
Examples
Let’s say that two jobs each validated a table and wrote the results to the results directory with write_results().
A later step of the process collects the results with a glob pattern (or just the directory) and checks the whole set:
multi = pb.MultiValidate.from_files(str(results / "*.json"))
len(multi), multi.all_passed()(2, False)
Only game_revenue has 2,000 rows, so the set doesn’t pass. Displaying multi (or its get_tabular_report()) would show why.