pandera icon indicating copy to clipboard operation
pandera copied to clipboard

Pydantic Model <-> jsonschema <-> Pandera Schema

Open cosmicBboy opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe.

See the problem articulated in #764

Describe the solution you'd like

In combination with #421, figure out a syntax for converting a pydantic model into a pandera schema, where the pydantic model constraints are converted into the most efficient built-in pandera checks so as to use the underlying optimized pandas methods.

The syntax could look something like:

pandera_schema = DataFrameSchema.from_pydantic_model(PydanticModel)

And for the class-based API:

# to avoid complications with inheritence, it may make sense to extend the
# pa.SchemaModel metaclass (model._MetaSchema) to accept a `pydantic_model`
# kwarg, where the metaclass handles the conversion.
class PanderaSchema(pa.SchemaModel, pydantic_model=PydanticModel):
    # additional pandera fields

    class Config:
        # additional pandera config

@jeffzi @ejmolinelli @tbsexton let me know if you have additional thoughts here!

cosmicBboy avatar Mar 26 '22 15:03 cosmicBboy