Convert YAML validation configuration to equivalent Python code.
USAGE
yaml_to_python(yaml)
This function takes a YAML validation configuration and generates the equivalent Python code that would produce the same validation workflow. This is useful for documentation, code generation, or learning how to translate YAML workflows into programmatic workflows.
The generated Python code includes all necessary imports, data loading, validation steps, and interrogation execution, formatted as executable Python code.
Parameters
yaml:Union[str, Path]
YAML configuration as string or file path. Can be: (1) a YAML string containing the validation configuration, or (2) a Path object or string path to a YAML file.
Returns
str
A formatted Python code string enclosed in markdown code blocks that replicates the YAML workflow. The code includes import statements, data loading, validation method calls, and interrogation execution.
Raises
:YAMLValidationError
If the YAML is invalid, malformed, or contains unknown validation methods.
Examples
Convert a basic YAML configuration to Python code:
import pointblank as pb# Define a YAML validation workflowyaml_config ='''tbl: small_tabletbl_name: Data Quality Checksteps:- col_vals_not_null: columns: [a, b]- col_vals_gt: columns: [c] value: 0'''# Generate equivalent Python codepython_code = pb.yaml_to_python(yaml_config)print(python_code)
The generated Python code shows exactly how to replicate the YAML workflow programmatically. This is particularly useful when transitioning from YAML-based workflows to code-based workflows, or when generating documentation that shows both YAML and Python approaches.
For more complex workflows with thresholds and metadata: