Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect "Type application has too few types" when constructing generic Series type #471

Closed
sebwills opened this issue Dec 15, 2022 · 6 comments · Fixed by #492
Closed

Comments

@sebwills
Copy link
Contributor

from pandera.typing import Series

x = Series[int]([1, 2, 3])

or

from pandera.typing import Series
import pandas as pd

df = pd.DataFrame([[1]], columns=['a'])
df['a'].pipe(Series[int])

cause mypy to produce errors like error: Type application has too few types (2 expected) [misc]

Please complete the following information:

  • OS: Windows + Linux
  • python version: 3.9
  • mypy==0.991
  • pandas-stubs==1.5.2.221213 (issue not present in 1.5.2.221124 and earlier)

Additional context

May be similar/same issue as #197 but for Series rather than DataFrames?

@bashtage
Copy link
Contributor

Why are you using Series from pandera? I think you might be in the wrong repo, as I don't think we support anything other than direct pandas use.

@sebwills
Copy link
Contributor Author

sebwills commented Dec 15, 2022

Well, I'm using pandera, which uses pandas-stubs, and I'm claiming a regression in pandas-stubs has broken pandera. Exactly like it was broken for pandera's DataFrame type in #197.

Here's a repro that doesn't involve pandera, hacked together from @cosmicBboy's repro in #197. It's mypy-happy with pandas-stubs 1.5.2.221124 and mypy-unhappy with 1.5.2.221213 (same error as above).

from typing import Generic, TypeVar

import pandas as pd

T = TypeVar("T")


class MySeries(pd.Series, Generic[T]):
    ...


def func() -> MySeries[float]:
    return MySeries[float]([1, 2, 3])

@bashtage
Copy link
Contributor

Can you write a reproducer using only pandas and not subclasses?

@sebwills
Copy link
Contributor Author

Can you write a reproducer using only pandas and not subclasses?

No, I don't think so.

Reading #197 more carefully I see that (assuming it's similar) it's caused by a mypy issue (python/mypy#13437 ). However, previously (#197) @Dr-Irv seemed happy to mitigate this with a change in pandas-stubs to avoid breaking pandera. Would be really helpful if a similar thing could be done here.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Dec 16, 2022

My current hypothesis on this is as follows:

  1. The error from mypy is correct. In pandas-stubs, Series is Generic and in the example above, MySeries is also Generic, so the error message error: Type application has too few types (2 expected) [misc] is saying that you need two types when declaring MySeries (one from MySeries, the other from Series)
  2. Why mypy picked this up in pandas-stubs v1..5.2.221213 and not in v1.5.2.221124 might be a mypy bug of some kind
  3. We'll have to try git bisect to determine the particular commit that changed the mypy behavior.

My sense now is that when we find the commit, it will be an innocuous change. I think the fundamental issue will be that to declare MySeries, you have to pass in two types to the declaration, i.e., something like MySeries[int,int] . That might not work well for pandera.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jan 2, 2023

git bisect reveals that commit dc9a094 caused things to change between stub versions 1.5.2.221124 and 1.5.2.221213

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants