Skip to content

ExcelFile parse of empty sheet fails with "IndexError: list index out of range" #6403

Closed
@myourshaw

Description

@myourshaw

Using pandas 0.13.1 on OS X Mavericks to parse a blank Excel spreadsheet causes "IndexError: list index out of range". Apparently the default header=0 in _parse_excel causes the execution of _trim_excel_header(data[header]). Perhaps when nrows==0 this should not be executed.

import pandas as pd
xl_file = pd.ExcelFile('blank.xlsx')
xl_file.parse('Sheet1') #Sheet1 has no data

STDERR:

Traceback (most recent call last):
  File "/Users/myourshaw/lab/pypeline/python2/excel_example.py", line 10, in <module>
    xl_file.parse('Sheet1')
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/io/excel.py", line 208, in parse
    **kwds)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/io/excel.py", line 291, in _parse_excel
    data[header] = _trim_excel_header(data[header])
IndexError: list index out of range

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions