Skip to main content

MultiValidate.filter()

Keep the runs that match.

Usage

Source

MultiValidate.filter(
    tbl_name=None,
    label=None,
    metadata=None,
)

The filter() method gives a new MultiValidate object with the runs whose table name, label, and metadata match all of the given conditions. This is useful for reporting on a part of the runs collected from a directory of results files, such as the runs of one table, or those of the production environment only.

Parameters

tbl_name: str | list[str] | None = None

The table name of the runs to keep, or a list of table names (a run is kept if it has any of them).

label: str | list[str] | None = None

The label of the runs to keep, or a list of labels.

metadata: dict[str, Any] | None = None
A dictionary of metadata that the runs to keep must have: each of its keys must be in the metadata of the run (given with write_results(metadata=)), with the same value. A validation that wasn’t read from a results file has no metadata, so it’s only kept without metadata=.

Returns

MultiValidate
A new MultiValidate object with the runs that match, in the same order and with the same order= setting. The runs aren’t copied, and the original object is unchanged.

Examples

Let’s say that a job validates the small_table dataset in two environments and writes the results with the environment in the metadata.

import pointblank as pb
import tempfile

results = tempfile.mkdtemp()

for k, env in enumerate(["dev", "prod", "prod"], start=1):
    validation = (
        pb.Validate(data=pb.load_dataset(dataset="small_table"), tbl_name="small_table")
        .col_vals_gt(columns="d", value=100)
        .interrogate()
    )
    pb.write_results(validation, f"run_{k}", path=results, metadata={"env": env})

multi = pb.MultiValidate.from_files(results)

len(multi), len(multi.filter(metadata={"env": "prod"}))
(3, 2)

Of the three runs, two were in the production environment. The filtered object has all the reports and roll-up methods of any MultiValidate object, so multi.filter(metadata={"env": "prod"}).all_passed() checks the production runs only.