Skip to content
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: read_csv's usecols type hint isn't match with list of strings #59530

Closed
3 tasks done
byildiz opened this issue Aug 16, 2024 · 2 comments
Closed
3 tasks done

BUG: read_csv's usecols type hint isn't match with list of strings #59530

byildiz opened this issue Aug 16, 2024 · 2 comments
Labels
Bug Closing Candidate May be closeable, needs more eyeballs Typing type annotations, mypy/pyright type checking

Comments

@byildiz
Copy link

byildiz commented Aug 16, 2024

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

import pandas as pd
df = pd.read_csv("test.csv", usecols=["a", "b"]) # this line causes type conflict

Issue Description

Pyright gives the following diagnostic message, but according to the pandas docs usecols can be a list of strings. I guess the type annotation of usecols is not accurate.

Diagnostics:
1. No overloads for "read_csv" match the provided arguments [reportCallIssue]
2. Argument of type "list[str]" cannot be assigned to parameter "usecols" of type "UsecolsArgType[Unknown]" in function "read_csv"
     Type "list[str]" is incompatible with type "UsecolsArgType[Unknown]"
       "list[str]" is incompatible with protocol "SequenceNotStr[Hashable]"
         "index" is an incompatible type
           Type "(value: str, start: SupportsIndex = 0, stop: SupportsIndex = sys.maxsize, /) -> int" is incompatible with type "(value: Any, /, start: int = 0, stop: int = ...) -> int"
             Missing keyword parameter "start"
             Missing keyword parameter "stop"
       "list[str]" is incompatible with "range"
       "list[str]" is incompatible with "ExtensionArray"
     ... [reportArgumentType]

Expected Behavior

The type annotation of usecols should accept list of strings.

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.11.9.final.0
python-bits : 64
OS : Darwin
OS-release : 22.6.0
Version : Darwin Kernel Version 22.6.0: Mon Jun 24 01:25:37 PDT 2024; root:xnu-8796.141.3.706.2~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.2
numpy : 2.0.1
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 70.1.0
pip : 24.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.4
IPython : None
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 : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.5
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 2.0.31
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

@byildiz byildiz added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 16, 2024
@byildiz byildiz changed the title BUG: read_csv usecols type hint isn't match with list of strings BUG: read_csv's usecols type hint isn't match with list of strings Aug 16, 2024
@rhshadrach
Copy link
Member

Thanks for the report. This is an issue for pandas-stubs. Can you open an issue here: https://github.com/pandas-dev/pandas-stubs/issues

@rhshadrach rhshadrach added Closing Candidate May be closeable, needs more eyeballs Typing type annotations, mypy/pyright type checking and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 16, 2024
@byildiz
Copy link
Author

byildiz commented Aug 16, 2024

It has already been there: pandas-dev/pandas-stubs#963. Sorry for the false alarm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Closing Candidate May be closeable, needs more eyeballs Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

No branches or pull requests

2 participants