-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: read_excel fails with IndexError: list index out of range #39250
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
Comments
full traceback please. I can't open this file with Excel (It tries to recover then fails) |
|
Yes, I have the same issue. However, my excel recovered the file and I can open it. |
I have figured out why the exception is arisen. The file, which I provided, can be read via xlrd <= 1.2.0 (maybe via even other xlrd versions, but not >= 2.0). However, pandas 1.2.0 uses openpyxl to read the file, if it is installed, that leads to the exception. |
yes, this is probably an In [131]: wb = openpyxl.load_workbook(path, read_only=False) # or read_only=True - which is what pandas actually uses, but it doesn't affect the results for this file
In [132]: wb.sheetnames
Out[132]: []
In [133]: wb.read_only
Out[133]: False
In [134]: wb.worksheets
Out[134]: []
|
did some digging - again - this is if anything an upstream issue. openpyxl has this block of code: # openpyxl/reader/excel.py in ExcelReader.read_worksheets
for sheet, rel in self.parser.find_sheets():
if rel.target not in self.valid_files: # this results in True for all the sheets
continue the if statement becomes True for all the sheets.
but the relationships file (
This probably indicates this is a malformed excel file (given that Excel also tries to "fix" the errors) - so openpyxl may be doing the right thing. I don't particularly intend on reading up the specs as to whether these should be case sensitive or not. Re-saving the zip after correctly capitalizing the 's' in 'sheetX.xml' in the rels file ( |
Yes, more accurate error message would be better. |
Thanks @YarShev for the report since this worked in 1.1.5, i'll label as regression.
further investigations/PRs welcome |
@simonjayhawkins The regression is because of the default engine being changed to openpyxl in 1.1.5, specifying There are many such issues where changing the engine has caused issues. #38956 #39001 and (#34747 (comment) on #34747) |
just to be clear
and this is unlikely to be changed. so any code that worked in 1.1.5 and does not in 1.2 should be considered a regression in the first instance (even if an upstream issue)
and the converse is also true, specifying
these should probably be labelled as regressions also (will look at these shortly) |
labelled #38956 and #39001 as regressions. For #34747, or indeed any issue with the openpyxl engine, since the default has changed could result in a regression from a user POV, we should consider backporting any fixes. |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
pandas : 1.2.0
numpy : 1.19.2
pytz : 2020.5
dateutil : 2.8.1
pip : 20.3.3
setuptools : 51.1.2.post20210112
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 : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.6
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
The file which read_excel fails on.
excel_sheetname_title.xlsx
The text was updated successfully, but these errors were encountered: