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: pandas.read_excel returns dict type if sheet_name=None #60909

Open
2 of 3 tasks
Filip-Regenczuk opened this issue Feb 11, 2025 · 3 comments · May be fixed by #60924
Open
2 of 3 tasks

BUG: pandas.read_excel returns dict type if sheet_name=None #60909

Filip-Regenczuk opened this issue Feb 11, 2025 · 3 comments · May be fixed by #60924
Labels
Docs IO Excel read_excel, to_excel

Comments

@Filip-Regenczuk
Copy link

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_excel("test_data/test.xlsx", sheet_name=None)
print(type(df))

Issue Description

Function pandas.read_excel when parameter sheet_name is set to None return dict object apart from pandas.core.frame.DataFrame.

Expected Behavior

It should return DF

Installed Versions

pandas==2.2.3

@Filip-Regenczuk Filip-Regenczuk added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 11, 2025
@Filip-Regenczuk
Copy link
Author

Important - it returns dict of DFs, what is not specified in documentation. It is misleading if excel file has only one sheet.

@asishm asishm added Docs and removed Bug labels Feb 11, 2025
@asishm
Copy link
Contributor

asishm commented Feb 11, 2025

Thanks for the report. This is intended. sheet_name=None will return always dict of dataframes (the docs do state that the read_excel method can return a dict of dataframes depending on the sheet_name parameter - which in turn states that using None would return ALL dataframes)

Relabeling as a docs request to maybe make this explicit in the docs.

@rhshadrach rhshadrach added IO Excel read_excel, to_excel and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 12, 2025
@rhshadrach
Copy link
Member

rhshadrach commented Feb 12, 2025

I think adding something like "When None, will return a dictionary containing DataFrames for each sheet" to the description of the sheets argument would be welcome!

It is misleading if excel file has only one sheet.

I think you're suggesting that pandas should return a DataFrame in the case where sheets=None and there is only one sheet in the Excel file. I am negative on making this change. The return type should be predictable from the arguments, and not depend on the data.

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

Successfully merging a pull request may close this issue.

3 participants