Skip to content

read_excel/index_col: string not accepted #809

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

Closed
clo-vis opened this issue Nov 3, 2023 · 3 comments · Fixed by #914
Closed

read_excel/index_col: string not accepted #809

clo-vis opened this issue Nov 3, 2023 · 3 comments · Fixed by #914
Labels
good first issue IO Excel read_excel, to_excel

Comments

@clo-vis
Copy link

clo-vis commented Nov 3, 2023

Either the documentation or the type hint for index_col in pandas.read_excel is wrong.

The documentation says a string may be used.

The type hint forbids that

Documentation:
index_col int, str, list of int, default None

Type hints:
index_col: int | Sequence[int] | None = ...,

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Nov 3, 2023

Looking internally at the pandas source, I think the docs may be wrong. Inside of pandas, index_col is typed without allowing str as an arg type.

If you can produce an example where read_excel() accepts a string (and maybe a list of strings??) as an argument for index_col, then updates should be made to the internal pandas source and the type hints.

Conversely, if a string doesn't work as the argument, then an issue should be raised in the pandas repo.

Can you provide an appropriate test (either way)?

@Dr-Irv Dr-Irv added IO Excel read_excel, to_excel Awaiting Response Waiting for response labels Nov 3, 2023
@clo-vis
Copy link
Author

clo-vis commented Nov 6, 2023

from pandas import read_excel
print(read_excel("Book1.xlsx"))
print(read_excel("Book1.xlsx", index_col="bar"))

Output:

   foo  bar
0    1    2
1    3    4
     foo
bar     
2      1
4      3

Book1.xlsx

@clo-vis clo-vis changed the title read_excel/index_col: contradiction between type hints and documentation read_excel/index_col: string not accepted Nov 6, 2023
@Dr-Irv Dr-Irv added good first issue and removed Awaiting Response Waiting for response labels Nov 6, 2023
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Nov 6, 2023

Thanks for the example. I created an issue for the pandas source to fix the typing there.

In the meantime, a fix here would be welcome, along with appropriate tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue IO Excel read_excel, to_excel
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants