Skip to content

epymorph.adrio.validation

ADRIO result validation utilities.

VALID module-attribute

VALID = Valid()

A singleton instance of Valid.

Validator module-attribute

The type for a function which validates a numpy result.

ValidationResult

Bases: ABC

The result of a data validation check.

See Also

epymorph.adrio.validation.Valid and epymorph.adrio.validation.Invalid.

is_valid abstractmethod property

is_valid: bool

True if this is a valid result, False for invalid.

Valid dataclass

Valid()

Bases: ValidationResult

The result of passing a validation check.

is_valid property

is_valid: Literal[True]

True if this is a valid result, False for invalid.

Invalid dataclass

Invalid(error: str)

Bases: ValidationResult

The result of failing a validation check.

error instance-attribute

error: str

The reason why this check failed..

is_valid property

is_valid: Literal[False]

True if this is a valid result, False for invalid.

ResultFormat dataclass

ResultFormat(
    shape: DataShape, dtype: dtype | type[generic]
)

Describes the properties of the expected result of evaluating an ADRIO.

Parameters:

  • shape (DataShape) –

    The expected shape of the result array.

  • dtype (dtype | type[generic]) –

    The dtype describing the result array.

shape instance-attribute

shape: DataShape

The expected shape of the result array.

dtype instance-attribute

dtype: dtype

The dtype describing the result array.

validate_pipe

validate_pipe(*validators: Validator) -> Validator

Creates a validator by chaining multiple other validators. Validators are evaluated such that they short-circuit on the first invalid result, in which case only that invalid result is returned. If all validators pass, Valid is returned.

Parameters:

  • *validators (Validator, default: () ) –

    The validator functions in evaluation order.

Returns:

validate_numpy

validate_numpy() -> Validator

Creates a validator which checks that the result is a numpy array.

Returns:

validate_values_in_range

validate_values_in_range(
    minimum: int | float | None, maximum: int | float | None
) -> Validator

Creates a validator which checks that numeric values fall within the specified range.

Assumes the values are not structured; if you wish to validate structured data combine this function with a wrapper like on_date_values or on_structured.

Parameters:

  • minimum (int | float | None) –

    The minimum valid value, or None if there is no minimum.

  • maximum (int | float | None) –

    The maximum valid value, or None if there is no maximum.

Returns:

validate_shape

validate_shape(shape: tuple[int, ...]) -> Validator

Creates a validator which checks the given shape.

Parameters:

  • shape (tuple[int, ...]) –

    The expected result shape.

Returns:

validate_shape_unchecked_arbitrary

validate_shape_unchecked_arbitrary(
    shape: tuple[int, ...],
) -> Validator

Creates a validator which checks the given shape with the special exception that if an axis is specified as -1, any length (one or greater) is permitted. There must still be the same number of dimensions in the result.

Parameters:

  • shape (tuple[int, ...]) –

    The expected result shape.

Returns:

validate_dtype

validate_dtype(dtype: dtype | type[generic]) -> Validator

Creates a validator which checks the given dtype.

Assumes the values are not structured; if you wish to validate structured data combine this function with a wrapper like on_date_values or on_structured.

Parameters:

Returns:

on_date_values

on_date_values(validator: Validator) -> Validator

Wraps a validator function so that it can check the values of a date/value array.

Parameters:

  • validator (Validator) –

    The validator function to wrap.

Returns:

  • Validator

    The validator function adapted to work for data/value arrays.

on_structured

on_structured(validator: Validator) -> Validator

Wraps a validator function so that it can check the values of structured arrays. This presumes that the validator can be applied to all elements of the structured array in the same way. That is: it will likely work for homogenous types but not heterogenous types.

Parameters:

  • validator (Validator) –

    The validator function to wrap.

Returns:

  • Validator

    The validator function adapated to work for structured arrays.

validate_result

validate_result(
    rformat: ResultFormat, context: Context
) -> Validator

Creates a validator for the given result format declaration. This is a shortcut for chaining validate_shape and validate_dtype.

Assumes the values are not structured; if you wish to validate structured data combine this function with a wrapper like on_date_values or on_structured.

Parameters:

  • rformat (ResultFormat) –

    The expected result format.

  • context (Context) –

    The simulation context.

Returns: