Description
-
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
from pathlib import Path
import pandas as pd
excel_file = Path("test_excel_file.xlsx")
table = pd.read_excel(excel_file, 'Taul1', header=[0, 1])
Problem description
Given table
A column | B column | C column |
---|---|---|
part 1 | part 2 | part 3 |
[empty] | [empty] | [empty] |
[empty] | [empty] | [empty] |
Row 1 Col A | Row 1 Col B | Row 1 Col C |
Row 2 Col A | Row 2 Col B | Row 2 Col C |
pd.read_excel with the new openpyxl-backend fails with exception
Traceback (most recent call last):
File "pandas_openpyxl_bug\test_pandas_openpyxl.py", line 12, in
table = pd.read_excel(excel_file, 'Taul1', header=[0, 1])
File ".virtualenvs\pandas_openpyxl_bug-3rzOJb6e\lib\site-packages\pandas\util_decorators.py", line 299, in wrapper
return func(*args, **kwargs)
File "virtualenvs\pandas_openpyxl_bug-3rzOJb6e\lib\site-packages\pandas\io\excel_base.py", line 344, in read_excel
data = io.parse(
File ".virtualenvs\pandas_openpyxl_bug-3rzOJb6e\lib\site-packages\pandas\io\excel_base.py", line 1170, in parse
return self._reader.parse(
File ".virtualenvs\pandas_openpyxl_bug-3rzOJb6e\lib\site-packages\pandas\io\excel_base.py", line 566, in parse
output[asheetname] = parser.read(nrows=nrows)
File ".virtualenvs\pandas_openpyxl_bug-3rzOJb6e\lib\site-packages\pandas\io\parsers.py", line 1057, in read
index, columns, col_dict = self._engine.read(nrows)
File ".virtualenvs\pandas_openpyxl_bug-3rzOJb6e\lib\site-packages\pandas\io\parsers.py", line 2503, in read
index, columns = self._make_index(data, alldata, columns, indexnamerow)
File ".virtualenvs\pandas_openpyxl_bug-3rzOJb6e\lib\site-packages\pandas\io\parsers.py", line 1566, in _make_index
index = index.set_names(indexnamerow[:coffset]) # type: ignore[union-attr]
AttributeError: 'NoneType' object has no attribute 'set_names'
Expected Output
A dataframe without a crash
Output of pd.show_versions()
INSTALLED VERSIONS
commit : f2c8480
python : 3.9.2.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : AMD64 Family 23 Model 8 Stepping 2, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Finnish_Finland.1252
pandas : 1.2.3
numpy : 1.20.1
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 53.0.0
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.7
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None