Skip to content

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

Open
@tvdboom

Description

@tvdboom

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    mypy bugRequires mypy to fix a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions