-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: DataFrame
argument columns
fails to type-check when passed a list of strings (pandas 2.2.0)
#56995
Comments
Seems that it boils down to Axes = ListLike And: The list of strings usage should have fitted into class SequenceNotStr(Protocol[_T_co]):
@overload
def __getitem__(self, index: SupportsIndex, /) -> _T_co:
...
@overload
def __getitem__(self, index: slice, /) -> Sequence[_T_co]:
...
def __contains__(self, value: object, /) -> bool:
...
def __len__(self) -> int:
...
def __iter__(self) -> Iterator[_T_co]:
...
def index(self, value: Any, /, start: int = 0, stop: int = ...) -> int:
...
def count(self, value: Any, /) -> int:
...
def __reversed__(self) -> Iterator[_T_co]:
... So if we further minimize the failing case:
Then:
So as can be seen the built-in |
I think this is already fixed on main: Line 152 in 21b3906
|
If you don't want to wait until the next pandas release:
|
Thanks for the prompt response! Sounds good (tested with pandas-stubs and no error was raised). |
This still seems to be an issue with 2.2.2 |
I'm also getting this type error with 2.2.2, 2.2.1, and 2.2.0. The version before that, 2.1.4, does not raise this error. (I am also using the latest pyright, pyright 1.1.381, for all of these.) |
I'm getting this issue with pandas 2.2.3 and pyright 1.1.383. |
This issue is fixed on main but did not make it into the 2.2.* releases. You will have to wait for 2.3/3.0 or install pandas-stubs. |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
Although the documentation shows that
columns
argument accepts a list of strings, the declared type annotation fails onpyright
type check. This issue showed up on pandas version 2.2.0Examples from the docs:
Expected Behavior
Passing a list of strings to the
columns
argument is expected to pass type check.Installed Versions
INSTALLED VERSIONS
commit : f538741
python : 3.10.11.final.0
python-bits : 64
OS : Windows
OS-release : 10
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 2.2.0
numpy : 1.26.1
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 23.3.1
Cython : None
pytest : 7.4.3
hypothesis : None
sphinx : 7.2.6
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.17.2
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
pyright
version: 1.1.347The text was updated successfully, but these errors were encountered: