unionai-oss / pandera

A light-weight, flexible, and expressive statistical data testing library
https://www.union.ai/pandera
MIT License
3.37k stars 310 forks source link

Accept pythonic schema model with @pa.check_io #889

Open pprados opened 2 years ago

pprados commented 2 years ago

Is your feature request related to a problem? Please describe. Accept pythonic class with @pa.check_io, without the invocation of .to_schema()

import pandas as pd
import pandera as pa
from pandera.typing import Index, DataFrame, Series

class Link1_schema(pa.SchemaModel):
    id: Index[int]
    data: Series[int]
    class Config:
        strict = True
        ordered = True

#@pa.check_io(data=Link1_schema.to_schema(), out=Link1_schema.to_schema()) # ACCEPTED
@pa.check_io(data=Link1_schema, out=Link1_schema) # ERROR
def f(data:pd.DataFrame[Link1_schema.to_schema()]) -> pd.DataFrame[Link1_schema.to_schema()]:
    #Link1_schema.validate(data)
    data['data']=2
    return data

d=DataFrame[Link1_schema]({"data":[1,2]})  # Validation lors de la création
f(d)

Describe the solution you'd like I would like to accept

@pa.check_io(data=Link1_schema, out=Link1_schema) # ERROR

Additional context The Schema Models must be equivalent of the Dataframe schema

cosmicBboy commented 2 years ago

To validate data using pa.SchemaModel subclasses, you need to use check_types instead of check_io