pandera icon indicating copy to clipboard operation
pandera copied to clipboard

Accept pythonic schema model with @pa.check_io

Open pprados opened this issue 1 year ago • 1 comments

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

pprados avatar Jul 18 '22 09:07 pprados

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

cosmicBboy avatar Jul 20 '22 14:07 cosmicBboy