pandera.api.dataframe.model.DataFrameModel
has unexpected generic subclass behaviour
#1764
Open
3 tasks done
Labels
bug
Something isn't working
Describe the bug
Typically in Python, when making a generic subclass of a generic type, you can provide
TypeVar
s as the type arguments to the base type. (See mypy docs for details.) However, creating a generic subclass ofpandera.api.dataframe.model.DataFrameModel
doesn't work as expected, and trying to instantiate the generic subclass with concrete type arguments raises a ValueError.Code Sample, a copy-pastable example
I've provided the expected Python behaviour alongside the current pandera behaviour.
Expected behavior
I'd expect the generic subclass (
Schema
above) to behave like a generic type.Desktop (please complete the following information):
Additional context
For now, this can be resolved by explicitly adding
Generic
to the subclass's bases:But with typical Python generics, this shouldn't be necessary. My guess is that overriding
__class_getitem__
source and returning a new type is different from what Python does. We should probably be returning atyping._GenericAlias
:The text was updated successfully, but these errors were encountered: