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

pd.Series gets converted to pd.TimestampSeries after isinstance check #877

Open
tvdboom opened this issue Feb 24, 2024 · 1 comment
Open
Labels
mypy bug Requires mypy to fix a bug

Comments

@tvdboom
Copy link

tvdboom commented Feb 24, 2024

Describe the bug
A pd.Series variable changes type after an isinstance check.

To Reproduce

  1. Provide a minimal runnable pandas example that is not properly checked by the stubs.
df1: pd.Series | pd.DataFrame = pd.Series()
reveal_type(df1)  # <- As expected
if isinstance(df1, pd.Series):
    reveal_type(df1)  # <- ???
  1. Indicate which type checker you are using (mypy or pyright).
    mypy
  2. Show the error message received from that type checker while checking your example.
note: Revealed type is "Union[pandas.core.series.Series[Any], pandas.core.frame.DataFrame]"
note: Revealed type is "pandas.core.series.TimestampSeries"

Please complete the following information:

  • OS: Windows
  • OS Version: 10
  • python version: 3.11
  • version of type checker: 1.8.0
  • version of installed pandas-stubs: 2.2.0.240218
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Feb 25, 2024

pyright 1.1.351 gets it right:

issue877.py:4:13 - information: Type of "df1" is "Series[Unknown]"
issue877.py:5:4 - error: Unnecessary isinstance call; "Series[Unknown]" is always an instance of "Series[Unknown]" (reportUnnecessaryIsInstance)
issue877.py:6:17 - information: Type of "df1" is "Series[Unknown]"

I think this is a mypy bug. See python/mypy#15322

I'll keep this open in case mypy ever fixes that issue.

@Dr-Irv Dr-Irv added the mypy bug Requires mypy to fix a bug label Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mypy bug Requires mypy to fix a bug
Projects
None yet
Development

No branches or pull requests

2 participants