unionai-oss / pandera

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

Inheritance of Config in SchemaModel #1024

Closed abyz0123 closed 1 year ago

abyz0123 commented 1 year ago

Describe the bug

!Not sure if a bug or design choice!

When inheriting a SchemaModel, I would expect that the Config class gets inherited with it, so that Schema-wide parameters such as unique are present in downstream model. This would be consistent with pydantic's handling thereof.

Also asked on SO here.

Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

from pandera import SchemaModel
from pandera.typing import Series

class Model1(SchemaModel):
    col1: Series[int]
    class Config:
        unique=['col1']

class Model2(Model1):
    col2: Series[str]

assert Model1.Config.unique == Model2.Config.unique

Expected behavior

Expected behaviour would be similar to pydantic.

from pydantic import BaseModel

class Model1(BaseModel):
    col1: str

    class Config:
        unique = ['col1']

class Model2(Model1):
    col2: str

assert Model1.Config.unique == Model2.Config.unique

Desktop (please complete the following information):

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

cosmicBboy commented 1 year ago

hi @abyz0123 check out the discussion here: https://github.com/unionai-oss/pandera/issues/983#issuecomment-1289623381

cosmicBboy commented 1 year ago

(in short, it's by design)

abyz0123 commented 1 year ago

Thanks for the quick follow-up, will close!