BUG: read_excel throws generic IndexError if header argument specifies non-existent rows · Issue #43143 · pandas-dev/pandas (original) (raw)

It doesn't seem to be based on a search for read_excel and indexerror


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

Given an excel file with one tab that contains the text header in cell A1 and nothing else:

In [1]: import pandas

In [2]: pandas.read_excel("~/temp/test_pandas/headers.xlsx", header=[0, 1])

IndexError Traceback (most recent call last)

snip - see comment below for full traceback

564                     if index_col is not None:

IndexError: list index out of range

Problem description

The code throws a (presumably unintended) IndexError, which is difficult to respond to as the actual cause of the error is not specified.

Expected Output

A ParserError (or other appropriate error type) with an error message that makes the cause of the problem clear.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 5f648bf
python : 3.9.6.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-154-generic
Version : #161-Ubuntu SMP Fri Jul 30 13:04:17 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.2
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 20.3.3
setuptools : 51.3.3
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.26.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
numba : None