import pointblank as pb
import tempfile
from pathlib import Path
config_dir = Path(tempfile.mkdtemp())
(config_dir / "pointblank" / "checks").mkdir(parents=True)
(config_dir / "pointblank" / "checks" / "ids.yaml").write_text('''
# @package checks.ids
steps:
- col_vals_not_null:
columns: ${vars.id_column}
- rows_distinct:
columns_subset: ${vars.id_column}
''')
id_checks = pb.hydra_steps("ids", vars={"id_column": "a"}, config_dir=config_dir)
id_checkshydra_steps()
Get a check collection as a Steps object.
Usage
hydra_steps(
name,
vars=None,
config_dir=None,
allow_python=False,
)A check collection is an option of the pointblank/checks config group: a YAML file with a list of validation steps, in a project’s own directory or in the config tree of an installed package. This gets the steps of one collection for use in a validation that’s written in Python, where they’re added with Validate.add_steps().
The arguments of each step are used as they’re written in the collection, as they are for the steps of a Contract, so the python: blocks of a collection aren’t run.
Parameters
name: str-
The collection, as it’s selected in a
defaults:list (e.g.,"ids"or"acme/emails"). vars: Mapping[str, Any] | None = None-
Values for the
${vars.<name>}interpolations in the collection. config_dir: str | Path | None = None-
A directory to add to the search path.
allow_python: bool = False-
Whether to make the mappings with a
_target_key into the Python objects they describe (such as a custom check that a package provides). Without this, a collection with a_target_raises an error. Only set it for collections that you trust.
Returns
Steps- The steps of the collection.
Raises
ImportError-
If neither
hydra-corenorlernais installed. YAMLValidationError- If there’s no such collection, or it has an interpolation with no value.
Examples
Let’s write a check collection to a temporary directory. The column it checks is left as a variable.
The steps can be added to any validation, alongside steps that are written in Python:
(
pb.Validate(data=pb.load_dataset("small_table"))
.add_steps(id_checks)
.col_vals_gt(columns="d", value=100)
.interrogate()
)The two steps of the collection come first in the validation, followed by the step that’s written in Python.