Closed
Description
Describe the bug
Pylance shows error when using a timestamp as label for selecting data from a pandas series.
To Reproduce
- Provide a minimal runnable
pandas
example that is not properly checked by the stubs.
import pandas as pd
dt1 = pd.to_datetime('2023-05-01')
dt2 = pd.to_datetime('2023-05-02')
s = pd.Series([1, 2], index=[dt1, dt2])
s[dt1] # pylance error here
s.loc[[dt1]] # pylance error here also
-
Indicate which type checker you are using (
mypy
orpyright
).
pyright -
Show the error message received from that type checker while checking your example.
Argument of type "Timestamp" cannot be assigned to parameter "idx" of type "int | _str" in function "getitem"
Type "Timestamp" cannot be assigned to type "int | _str"
"Timestamp" is incompatible with "int"
"Timestamp" is incompatible with "_str"PylancereportGeneralTypeIssues
Please complete the following information:
- OS: MacOS Monterey
- OS Version: 12.3.1
- python version: 3.10.8
- version of type checker: pylance v2023.3.40
- version of installed
pandas-stubs
: 1.5.3.230321
Additional context
Same issue arises when using timedelta instead of timestamp.