pandera
pandera copied to clipboard
Pydantic compatibility issue
I believe that the latest versions of Pydantic and Pandera are not fully compatible.
This relates to https://github.com/unionai-oss/pandera/issues/1395 which was closed, but I think should still be open
- [x] I have checked that this issue has not already been reported.
- [x] I have confirmed this bug exists on the latest version of pandera.
This code throws an error:
import pandas as pd
import pandera as pa
from pandera.typing import DataFrame, Series
import pydantic
class SimpleSchema(pa.DataFrameModel):
str_col: Series[str] = pa.Field(unique=True)
class PydanticModel(pydantic.BaseModel):
x: int
df: DataFrame[SimpleSchema]
print(PydanticModel.model_json_schema())
error message:
Exception has occurred: PydanticInvalidForJsonSchema
Cannot generate a JsonSchema for core_schema.PlainValidatorFunctionSchema ({'type': 'no-info', 'function': functools.partial(<bound method DataFrame.pydantic_validate of <class 'pandera.typing.pandas.DataFrame'>>, schema_model=SimpleSchema)})
For further information visit https://errors.pydantic.dev/2.7/u/invalid-for-json-schema
File "C:\LocalTemp\Repos\RA\RiskCalcs\scratch.py", line 18, in <module>
print(PydanticModel.model_json_schema())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic.errors.PydanticInvalidForJsonSchema: Cannot generate a JsonSchema for core_schema.PlainValidatorFunctionSchema ({'type': 'no-info', 'function': functools.partial(<bound method DataFrame.pydantic_validate of <class 'pandera.typing.pandas.DataFrame'>>, schema_model=SimpleSchema)})
For further information visit https://errors.pydantic.dev/2.7/u/invalid-for-json-schema
I have tried various config options to get around this error to no avail.
- OS: Windows
- Pydantic version: 2.7.3
- Pandera version: 0.19.3