aw.validation¶
Validation system supporting three flavors: schema, info-dict, and functional.
This module provides validators that can be used to check if artifacts meet requirements. Validators follow the pattern:
validator(artifact) -> (success: bool, info: dict)
Functions
|
Combine multiple validators - all must pass. |
|
Combine multiple validators - at least one must pass. |
|
Create a validator that tries to use the artifact for its purpose. |
|
Validator that checks artifact has required attributes. |
|
Create a validator that computes info then checks it. |
Validator that checks artifact is not empty. |
|
|
Validator that checks artifact type. |
|
Create a validator from a schema (Pydantic, JSON Schema, etc.). |
- aw.validation.all_validators(*validators)[source]¶
Combine multiple validators - all must pass.
- Parameters:
*validators (
Callable) – Validator functions to combine- Return type:
- Returns:
A validator that passes only if all validators pass
Example
>>> validate = all_validators( ... is_dataframe, ... has_required_columns(['x', 'y']), ... has_no_nulls ... )
- aw.validation.any_validator(*validators)[source]¶
Combine multiple validators - at least one must pass.
- aw.validation.functional_validator(try_function, success_check=None)[source]¶
Create a validator that tries to use the artifact for its purpose.
This validator actually attempts to use the artifact in the way it’s intended to be used (e.g., try to visualize the data, try to train a model).
- Parameters:
- Return type:
- Returns:
A validator function
Example
>>> def try_cosmo(df): ... return cosmograph.cosmo(df, points_x_by='x', points_y_by='y') >>> validate = functional_validator(try_cosmo) >>> validate(df)
- aw.validation.has_attributes(**required_attrs)[source]¶
Validator that checks artifact has required attributes.
Example
>>> validate = has_attributes(shape=lambda s: len(s) == 2, columns=lambda c: len(c) > 0)
- aw.validation.info_dict_validator(compute_info, check_info)[source]¶
Create a validator that computes info then checks it.
This is a two-stage validator:
Compute information about the artifact (e.g., df.shape, df.dtypes)
Check if that information meets requirements
- Parameters:
- Return type:
- Returns:
A validator function
Example
>>> def compute_df_info(df): ... return {'shape': df.shape, 'null_count': df.isnull().sum().sum()} >>> def check_df_info(info): ... if info['null_count'] > 10: ... return False, "Too many nulls" ... return True, "OK" >>> validate = info_dict_validator(compute_df_info, check_df_info)
- aw.validation.is_not_empty()[source]¶
Validator that checks artifact is not empty.
Works for sequences, mappings, DataFrames, etc.
- aw.validation.is_type(expected_type)[source]¶
Validator that checks artifact type.
Example
>>> import pandas as pd >>> validate = is_type(pd.DataFrame)
- aw.validation.schema_validator(schema)[source]¶
Create a validator from a schema (Pydantic, JSON Schema, etc.).
- Parameters:
schema (
Any) – A schema object with validation capability- Return type:
- Returns:
A validator function
Example
>>> from pydantic import BaseModel >>> class DataSchema(BaseModel): ... x: float ... y: float >>> validate = schema_validator(DataSchema) >>> validate({'x': 1.0, 'y': 2.0}) (True, {'validated': ...})