Skip to content

DataFrame.loc does not like Sequence[Hashable] for the columns #1410

@cmp0xff

Description

@cmp0xff

Describe the bug

DataFrame.loc does not like Sequence[Hashable] for the columns

To Reproduce

Script

from collections.abc import Hashable, Sequence
from typing import cast

import pandas as pd

a = cast(Sequence[Hashable], ["a"])
pd.DataFrame({"a": [1]}).loc[:, a]

Typechecker

pyright

Error message

  ttest.py:7:1 - error: No overloads for "__getitem__" match the provided arguments (reportCallIssue)
  ttest.py:7:1 - error: Argument of type "tuple[slice[None, None, None], Sequence[Hashable]]" cannot be assigned to parameter "idx" of type "tuple[Scalar, slice[Any, Any, Any]]" in function "__getitem__"
    "tuple[slice[None, None, None], Sequence[Hashable]]" is not assignable to "tuple[Scalar, slice[Any, Any, Any]]"
      Tuple entry 1 is incorrect type
        Type "slice[None, None, None]" is not assignable to type "Scalar"
          "slice[None, None, None]" is not assignable to "str"
          "slice[None, None, None]" is not assignable to "bytes"
          "slice[None, None, None]" is not assignable to "date"
          "slice[None, None, None]" is not assignable to "datetime"
          "slice[None, None, None]" is not assignable to "timedelta" (reportArgumentType)     
2 errors, 0 warnings, 0 informations

Informations

  • version of type checker: 1.1.406
  • version of installed pandas-stubs: main

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions