-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
usecols keyword argument of pd.read_csv says it expects list[str] but the documentation says otherwise #605
Comments
Need to change pandas-stubs/pandas-stubs/io/parsers/readers.pyi Lines 45 to 52 in 2e3bbe8
to change list[str] to list[HashableT] and Callable[[str], bool] to Callable[[Hashable], bool]
Also change other places in that file that have the PR with tests welcome. Tests should be added near here: Line 518 in 2e3bbe8
|
* gh-623: broaden 'names' param of read_csv Broaden the type hint for the 'names' param of read_csv (and read_table, which behaves similarly) from previous list[str], so that other valid types are accepted by mypy. * allow None as names param of read_clipboard Noticed as I found clipboard after the changes to read_csv and read_table, and it calls it, so should match - but it was missing None as an option. * broaden 'names' param of read_clipboard Match prior change to read_csv, since read_clipboard calls read_csv. * broaden 'names' param of read_excel Match prior change to read_csv, read_table, read_clipboard. * gh-605: broader usecols param type hint This fixes the pycharm tooltip problem in gh-605, as well as allowing more list-like types of strings (tuples of strings, as well as mutable sequences of strings other than list), and callables that accept hashables, not just strings. * test that read_excel accepts string for usecols * test names and usecols correctly exclude strings Strings aren't valid arguments here (except for read_excel, where we have a test now to check that this is accepted). Adding tests to make sure the type hints aren't overly wide and accept string arguments by mistake.
When will the changes be made public? meaning I can do |
Unsure at the moment. I would like the next release to support the 2.0 features, but there is work described in #624 that needs to get done. If you can't wait for that work to get done, I believe that you could just clone the repo, switch to the |
Describe the bug
usecols
keyword argument ofpd.read_csv
says it expectslist[str]
but the documentation says otherwise:Documentation (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html):
To Reproduce
pandas
example that is not properly checked by the stubs.import pandas as pd; path_to_csv = "mycsv.csv"; df_db = pd.read_csv(path_to_csv, usecols=[0])
mypy
orpyright
). PyCharm default type-checker, I haven't checkedmypy
.Please complete the following information:
3.11.1
mypy 1.1.1
pandas-stubs
pandas-stubs 1.5.3.230321
Additional context
Realted to this SO post.
The text was updated successfully, but these errors were encountered: