Skip to content

Dynamical schema using SchemaModel #1067

Discussion options

You must be logged in to vote

hi @alejandro-yousef so at the end of the day SchemaModel is converted to a DataFrameSchema when you call SchemaModel.validate, so you can do something like:

class  MySchema(pa.SchemaModel):
    dynamic_column: pa.typing.Series[float]


def fn(data: pd.DataFrame, runtime_column_name: str):
    ... # do stuff
    return (
        SchemaModel.to_schema()
        # use any of the schema transformation methods:
        # https://pandera.readthedocs.io/en/stable/dataframe_schemas.html#dataframeschema-transformations
        .update_column(dynamic_column={"name": runtime_column_name})  # add run-time columns
        .validate(data)
    )

If you wanted something fancier you can extend the Schema…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by cosmicBboy
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #1065 on January 11, 2023 16:25.