Closed
Description
Describe the bug
DataFrame.loc[] should accept list[str] as stated in the pandas docs: "A list or array of labels, e.g. ['a', 'b', 'c']."
To Reproduce
import pandas as pd
df = pd.DataFrame([[1, 2], [4, 5], [7, 8]],
index=['cobra', 'viper', 'sidewinder'],
columns=['max_speed', 'shield'])
df.loc[['viper', 'sidewinder']]
$ mypy pd_test.py
pd_test.py:7: error: Invalid index type "list[str]" for "_LocIndexerFrame[DataFrame]"; expected type "slice[Any, Any, Any] | ndarray[Any, dtype[integer[Any]]] | Index[Any] | list[int] | Series[int] | <6 more items>" [index]
Found 1 error in 1 file (checked 1 source file)
1
Please complete the following information:
- OS: Linux
- OS Version: Ubuntu 24.04.2 LTS
- python version: 3.12.9
- version of type checker: mypy 1.15.0 (compiled: yes)
- version of installed
pandas-stubs
: 2.2.3.250308