Skip to content

Remove columns on a SchemaModel #990

Answered by cosmicBboy
a-recknagel asked this question in Q&A
Discussion options

You must be logged in to vote

hey @a-recknagel so unfortunately using SchemaModels in this way isn't possible because inheritence is only additive.

It's perhaps a little less intuitive, but if you want to rely on Python's inheritence semantics, I typically use this pattern:

import pandera as pa
from pandera.typing import DataFrame, Series

class BaseSchema(pa.SchemaModel):
    # put all the common columns here
    a: Series[int]
    b: Series[int]

class SchemaA(BaseSchema):
    c: Series[int]
    d: Series[int]

class SchemaB(BaseSchema):
    # suppose you drop but also add a bunch of columns. This is equivalent to
    # dropping "a" and "b" and adding "e" and "f"
    e: Series[int]
    f: Series[int]

This can get ov…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by a-recknagel
Comment options

You must be logged in to vote
0 replies
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
enhancement New feature or request
2 participants
Converted from issue

This discussion was converted from issue #987 on October 28, 2022 13:35.