Skip to content

Using Timestamp as label when indexing with [] gives typing error. #620

Closed
@soylander

Description

@soylander

Describe the bug
Pylance shows error when using a timestamp as label for selecting data from a pandas series.

To Reproduce

  1. 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
  1. Indicate which type checker you are using (mypy or pyright).
    pyright

  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    IndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions