Skip to main content

read_results()

Read the results of a validation from a file written by write_results().

Usage

Source

read_results(filepath)

This gives a Validate object with the results of the run in the file: its steps, their results, and the metadata of the run. All of the reports work on it, as on the original validation: the validation report (with get_tabular_report() or by printing the object), get_json_report(), get_dataframe_report(), the verdict methods (all_passed(), assert_below_threshold(), …), the counts and fractions by step (n_passed(), …), and get_health_score(). It can also be one of the validations in a MultiValidate object.

A results file holds no table, no data extracts, and no validation plan that could be run, so the methods that need them (interrogate(), get_data_extracts(), get_sundered_data(), get_row_flags(), get_step_report(), to_code(), to_yaml(), and add_steps()) raise an error. The pre= functions, expressions, and other values that a results file keeps only as a description come back as objects that print as that description (e.g., the source code of a function), for the reports.

Reading a results file runs no code, so it’s safe to read one from any source.

Parameters

filepath: str | Path
The path of the results file. The .json extension is added if the path has no extension.

Returns

Validate
A validation with the results of the run in the file.

Examples

Let’s write the results of a validation to a file, and read them back:

import pointblank as pb
import os
import tempfile

validation = (
    pb.Validate(
        data=pb.load_dataset("small_table"),
        tbl_name="small_table",
        label="Nightly check",
        thresholds=(0.1, 0.25),
    )
    .col_vals_gt(columns="d", value=1000)
    .col_vals_le(columns="c", value=pb.col("d"))
    .col_vals_not_null(columns="c")
    .interrogate()
)

results_dir = tempfile.mkdtemp()
pb.write_results(validation, "nightly", path=results_dir)

restored = pb.read_results(os.path.join(results_dir, "nightly.json"))

restored
Pointblank Validation
Nightly check
Polarssmall_tableWARNING0.1ERROR0.25CRITICAL—
STEP COLUMNS VALUES TBL EVAL UNITS PASS FAIL W E C EXT
#EBBC14 1
col_vals_gt
col_vals_gt()
d 1000 ✓ 13 7
0.54
6
0.46
● ● — —
#AAAAAA 2
col_vals_le
col_vals_le()
c d ✓ 13 11
0.85
2
0.15
● ○ — —
#AAAAAA 3
col_vals_not_null
col_vals_not_null()
c — ✓ 13 11
0.85
2
0.15
● ○ — —

The report is the same as the report of the original validation, except that there are no data extracts to download (the EXT column has a dash for every step). The verdict methods work as on the original, too:

restored.all_passed(), restored.n_failed(i=1, scalar=True)
(False, 6)

The first step has 6 failing test units, so not all of the steps passed.

See Also

write_results()

Write the results of an interrogated validation to a JSON file.

from_files()

Read several results files into one MultiValidate object.

read_file()

Load a whole validation object saved with write_file().