-
-
Notifications
You must be signed in to change notification settings - Fork 147
Description
Describe the bug
Hi all, first off thanks for this effort! We use pandas-stubs
in the pandera
project for optional mypy type linting and it's been working great!
Recent changes (here) have caused issues in pandera type annotation, where we use a pandera SchemaModel
in a subclassed DataFrame class like so:
class MySchema(pandera.SchemaModel): ...
# then you can initialize a validated dataframe like so:
vaildated_data = pandera.typing.DataFrame[MySchema](data)
However, this will raise a mypy error if pandas-stubs
is installed:
Type application has too few types (2 expected)
To Reproduce
Consider this code, which subclasses dataframes :
# bar.py
from typing import Generic, TypeVar
import pandas as pd
T = TypeVar("T")
class MyDataFrame(pd.DataFrame, Generic[T]):
...
def func() -> MyDataFrame[int]:
return MyDataFrame[int]({"foo": [1, 2, 3]})
Then using mypy
:
mypy bar.py
# bar.py:14: error: Type application has too few types (2 expected) [misc]
# Found 1 error in 1 file (checked 1 source file)
I've isolated the cause of this here, where removing the ListLike
type annotations (including the one in the Iterable
type) makes the error go away. I don't understand why the type annotations in the __new__
method would effect the type of the subclassed generic arguments 🤷♂️
Please complete the following information:
- OS: MacOS
- OS Version: 10.15.7
- python version: 3.9.12
- version of type checker: mypy==0.971
- version of installed
pandas-stubs
: 1.4.3.220815
Additional context
This issue doesn't show up in the previous version pandas-stubs==1.4.3.220807