abraxos.validate.validate

abraxos.validate.validate(df, model)[source]

Validates each row in a DataFrame using a Pydantic-like model.

Each record is passed to the model’s model_validate method. Successfully validated models are converted back into rows using model_dump.

Parameters:
  • df (pd.DataFrame) – The DataFrame containing records to be validated.

  • model (type[PydanticModel] or PydanticModel) – A Pydantic-style model class or instance with model_validate and model_dump methods.

Returns:

A named tuple with: - errors: List of exceptions raised during validation. - errored_df: DataFrame of rows that failed validation. - success_df: DataFrame of rows that were successfully validated.

Return type:

ValidateResult

Examples

>>> import pandas as pd
>>> from pydantic import BaseModel
>>> class Person(BaseModel):
...     name: str
...     age: int
>>> df = pd.DataFrame({'name': ['Alice', 'Bob'], 'age': [30, 'invalid']})
>>> result = validate(df, Person)
>>> len(result.success_df)
1
>>> len(result.errored_df)
1