-
-
Notifications
You must be signed in to change notification settings - Fork 154
Description
Describe the bug
The type of a Series constructed from a list[float|str] is deduced as Series[bool]. Which it definitely isn't.
To Reproduce
Provide a minimal runnable pandas example that is not properly checked by the stubs.
from __future__ import annotations
from typing import TYPE_CHECKING
import pandas as pd
def func() -> pd.Series[str|float]:
values: list[str|float] = ["foo", "bar", 1.0]
if TYPE_CHECKING:
reveal_type(values)
reveal_type(pd.Series(values))
return pd.Series(values)
print(func())
Indicate which type checker you are using (mypy or pyright).
mypy
Show the error message received from that type checker while checking your example.
pandas_stubs_issue.py:10: note: Revealed type is "builtins.list[builtins.str | builtins.float]"
pandas_stubs_issue.py:11: note: Revealed type is "pandas.core.series.Series[builtins.bool]"
pandas_stubs_issue.py:12: error: Incompatible return value type (got "Series[bool]", expected "Series[str | float]")
[return-value]
return pd.Series(values)
^~~~~~~~~~~~~~~~~
Found 1 error in 1 file (checked 1 source file)
Please complete the following information:
OS: Windows
Version: 11
Python version: 3.12.9
version of type checker: mypy 1.17.1 (compiled: yes)
version of installed pandas-stubs: "Version: 2.3.3.251201"
Additional context
The same doesn't happen with a list[str] in place of the list[str|float]: the type is deduced as pd.Series[str] in that case.
The same doesn't happen with the previous pandas-stubs version 2.3.2.250926: the type is deduced as pd.Series[str|float]