Skip to content

BUG: read_excel fails when empty sheets exist and sheetname=None #11711 #11819

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

Merged
merged 1 commit into from
Dec 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.18.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,5 @@ Bug Fixes


- Bug in ``df.replace`` while replacing value in mixed dtype ``Dataframe`` (:issue:`11698`)

- Bug in ``read_excel`` failing to read any non-empty sheets when empty sheets exist and ``sheetname=None`` (:issue:`11711`)
3 changes: 2 additions & 1 deletion pandas/io/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ def _parse_cell(cell_contents,cell_typ):
data.append(row)

if sheet.nrows == 0:
return DataFrame()
output[asheetname] = DataFrame()
continue

if com.is_list_like(header) and len(header) == 1:
header = header[0]
Expand Down
9 changes: 9 additions & 0 deletions pandas/io/tests/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,15 @@ def test_reading_multiple_specific_sheets(self):
tm.assert_contains_all(expected_keys, dfs.keys())
assert len(expected_keys) == len(dfs.keys())

def test_reading_all_sheets_with_blank(self):
# Test reading all sheetnames by setting sheetname to None,
# In the case where some sheets are blank.
# Issue #11711
basename = 'blank_with_header'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you didn't commit the test files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reusing existing test files in pandas/io/tests/data/blank_with_header.xls*

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh ok, saw it fail but didn't look at the reason, ok then!

dfs = self.get_exceldf(basename, sheetname=None)
expected_keys = ['Sheet1', 'Sheet2', 'Sheet3']
tm.assert_contains_all(expected_keys, dfs.keys())

# GH6403
def test_read_excel_blank(self):
actual = self.get_exceldf('blank', 'Sheet1')
Expand Down