Skip to content

Commit 4979f7a

Browse files
committed
Merge pull request #11819 from sxwang/read_excel_empty
BUG: read_excel fails when empty sheets exist and sheetname=None #11711
2 parents 218cba6 + 9df5fb8 commit 4979f7a

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

doc/source/whatsnew/v0.18.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,5 @@ Bug Fixes
231231

232232

233233
- Bug in ``df.replace`` while replacing value in mixed dtype ``Dataframe`` (:issue:`11698`)
234+
235+
- Bug in ``read_excel`` failing to read any non-empty sheets when empty sheets exist and ``sheetname=None`` (:issue:`11711`)

pandas/io/excel.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,8 @@ def _parse_cell(cell_contents,cell_typ):
391391
data.append(row)
392392

393393
if sheet.nrows == 0:
394-
return DataFrame()
394+
output[asheetname] = DataFrame()
395+
continue
395396

396397
if com.is_list_like(header) and len(header) == 1:
397398
header = header[0]

pandas/io/tests/test_excel.py

+9
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,15 @@ def test_reading_multiple_specific_sheets(self):
382382
tm.assert_contains_all(expected_keys, dfs.keys())
383383
assert len(expected_keys) == len(dfs.keys())
384384

385+
def test_reading_all_sheets_with_blank(self):
386+
# Test reading all sheetnames by setting sheetname to None,
387+
# In the case where some sheets are blank.
388+
# Issue #11711
389+
basename = 'blank_with_header'
390+
dfs = self.get_exceldf(basename, sheetname=None)
391+
expected_keys = ['Sheet1', 'Sheet2', 'Sheet3']
392+
tm.assert_contains_all(expected_keys, dfs.keys())
393+
385394
# GH6403
386395
def test_read_excel_blank(self):
387396
actual = self.get_exceldf('blank', 'Sheet1')

0 commit comments

Comments
 (0)