Closed
Description
Describe the bug
Series#__getitem__
doesn't accept pd.Timestamp
To Reproduce
from __future__ import annotations
import pandas as pd
index = pd.date_range("2018-01-01", periods=5, freq="D")
series = pd.Series([1, 2, 3, 4, 5], index=index)
value = series[index[-1]] # error
print(value)
mypy
output:
test.py:7: error: No overload variant of "__getitem__" of "Series" matches argument type "Timestamp" [call-overload]
test.py:7: note: Possible overload variants:
test.py:7: note: def __getitem__(self, list[str] | Index[Any] | Series[Any] | slice | Series[bool] | ndarray[Any, dtype[bool_]] | list[bool] | tuple[Any | slice, ...], /) -> Series[Any]
test.py:7: note: def __getitem__(self, int | str, /) -> Any
Found 1 error in 1 file (checked 1 source file)
Until it's fixed in pandas-stubs
this can be used as a quick-fix:
-value = series[index[-1]]
+value = series.loc[index[-1]]
Please complete the following information:
- OS: macOS Ventura 13.5.2 (22G91)
- Python: 3.10.12
- Mypy: 1.5.1 (compiled: yes)
pandas-stubs
: 2.0.3.230814