Skip to content

BUG: set_index rejects List[str] #153

Closed
@bashtage

Description

@bashtage

Describe the bug
A clear and concise description of what the bug is.

To Reproduce

import pandas as pd

df = pd.DataFrame({"a":[1,2,3]})
_l: list[str] = ["a","b","c"]
df.set_index(_l)

Error with mypy 0.971 is

exp.py:5: error: Argument 1 to "set_index" of "DataFrame" has incompatible type "List[str]"; expected "Union[Optional[Hashable], Series[Any], Index, ndarray[Any, Any], Iterator[Hashable], List[Hashable]]"
exp.py:5: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
exp.py:5: note: Consider using "Sequence" instead, which is covariant
exp.py:5: note: "list" is missing following "Iterator" protocol member:
exp.py:5: note:     __next__

Please complete the following information:

  • OS: Windows
  • OS Version 11
  • python version: 3.10
  • version of type checker: mypy
  • version of installed pandas-stubs: 1.4.3.220718

Additional context
Looks like a regression in #147

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