-
-
Notifications
You must be signed in to change notification settings - Fork 147
Open
Description
Describe the bug
+
(__add__
) between Series and Timedeltas is broken in 2.3.2, still works in 2.3.1 (the code still works so I'm assuming it's a pandas-stubs issue)
To Reproduce
about as small as I can get it
import pandas as pd
_ = pd.Series() + pd.Timedelta(hours=2)
result (using tox which runs mypy with these settings, and I don't think any other magic?):
type: commands[1]> mypy --warn-return-any --warn-unreachable --check-untyped-defs --no-namespace-packages ./app ./tests
tests/isolated example.py:5: error: No overload variant of "__add__" of "Series" matches argument type "Timedelta" [operator]
tests/isolated example.py:5: note: Possible overload variants:
tests/isolated example.py:5: note: def __add__(self, str, /) -> Never
tests/isolated example.py:5: note: def __add__(self, complex | ExtensionArray | ndarray[tuple[Any, ...], dtype[Any]] | dict[str, ndarray[tuple[Any, ...], dtype[Any]]] | SequenceNotStr[Any] | Series[Any], /) -> Series[Any]
tests/isolated example.py:5: note: def __add__(self, Series[Never], /) -> Series[Any]
tests/isolated example.py:5: note: def [_T_COMPLEX: complex] __add__(self, _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX], /) -> Series[_T_COMPLEX]
tests/isolated example.py:5: note: def __add__(self, ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]], /) -> Series[bool]
tests/isolated example.py:5: note: def __add__(self, ndarray[tuple[Any, ...], dtype[integer[Any]]], /) -> Series[int]
tests/isolated example.py:5: note: def __add__(self, ndarray[tuple[Any, ...], dtype[floating[Any]]], /) -> Series[float]
tests/isolated example.py:5: note: def __add__(self, ndarray[tuple[Any, ...], dtype[complexfloating[Any, Any]]], /) -> Series[complex]
tests/isolated example.py:5: note: def __add__(self, builtins.bool | Sequence[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | ndarray[tuple[Any, ...], dtype[integer[Any]]] | Series[builtins.bool], /) -> Series[int]
tests/isolated example.py:5: note: def [_T_INT: int] __add__(self, int | Sequence[int] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | ndarray[tuple[Any, ...], dtype[integer[Any]]] | ndarray[tuple[Any, ...], dtype[floating[Any]]] | Series[_T_INT], /) -> Series[float]
tests/isolated example.py:5: note: def [_T_COMPLEX: complex] __add__(self, _T_COMPLEX | Sequence[_T_COMPLEX] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | ndarray[tuple[Any, ...], dtype[integer[Any]]] | ndarray[tuple[Any, ...], dtype[floating[Any]]] | ndarray[tuple[Any, ...], dtype[complexfloating[Any, Any]]] | Series[_T_COMPLEX], /) -> Series[complex]
tests/isolated example.py:5: note: def __add__(self, ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | ndarray[tuple[Any, ...], dtype[integer[Any]]] | ndarray[tuple[Any, ...], dtype[floating[Any]]] | ndarray[tuple[Any, ...], dtype[complexfloating[Any, Any]]], /) -> Never
tests/isolated example.py:5: note: def __add__(self, str | Sequence[str] | ndarray[tuple[Any, ...], dtype[str_]] | Series[str], /) -> Series[str]
interestingly: this doesn't trigger it somehow, which is actually closer to the code where I encountered the bug, but the minimal example works so idk:
import pandas as pd
def fun(s: pd.DataFrame) -> pd.Series:
return s["some_column"] + pd.Timedelta(hours=1)
Please complete the following information:
- OS: linux
- OS Version: Kubuntu 25.04
- python version 3.12.4
- version of type checker: mypy: 1.17.1
- version of installed
pandas-stubs
: 2.3.2 (broken) 2.3.1 (works)
Metadata
Metadata
Assignees
Labels
No labels