Skip to content

dataframe to_excel issue with openpyxl > 3.0.1 #30203

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

Closed
mhooreman opened this issue Dec 11, 2019 · 5 comments
Closed

dataframe to_excel issue with openpyxl > 3.0.1 #30203

mhooreman opened this issue Dec 11, 2019 · 5 comments
Labels
IO Excel read_excel, to_excel

Comments

@mhooreman
Copy link

Hello,

When exporting a data frame to excel on a python setup using openpyxl 3.0.2, we have the error TypeError: got invalid input value of type <class 'xml.etree.ElementTree.Element'>, expected string or Element.

Rolling back to 3.0.1 solves the issue.

Thanks

Code Sample

With openpyxl 3.0.2

>>> import openpyxl
>>> openpyxl.__version__
'3.0.2'
>>> import pandas as pd
>>> pd.DataFrame(dict(x=range(10))).to_excel('test.xlsx')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  [...]
  File "src/lxml/serializer.pxi", line 1652, in lxml.etree._IncrementalFileWriter.write
TypeError: got invalid input value of type <class 'xml.etree.ElementTree.Element'>, expected string or Element

With openpyxl 3.0.1

>>> import openpyxl
>>> openpyxl.__version__
'3.0.1'
>>> import pandas as pd
>>> pd.DataFrame(dict(x=range(10))).to_excel('test.xlsx')
>>> 

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit           : None
python           : 3.7.4.final.0
python-bits      : 64
OS               : Linux
OS-release       : 4.15.0-72-generic
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 0.25.3
numpy            : 1.17.4
pytz             : 2019.3
dateutil         : 2.8.1
pip              : 19.3.1
setuptools       : 41.4.0
Cython           : 0.29.14
pytest           : None
hypothesis       : None
sphinx           : 2.2.2
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : 4.4.2
html5lib         : None
pymysql          : None
psycopg2         : 2.8.4 (dt dec pq3 ext lo64)
jinja2           : 2.10.3
IPython          : 7.10.1
pandas_datareader: None
bs4              : 4.8.1
bottleneck       : 1.3.1
fastparquet      : None
gcsfs            : None
lxml.etree       : 4.4.2
matplotlib       : 3.1.2
numexpr          : 2.7.0
odfpy            : None
openpyxl         : 3.0.2
pandas_gbq       : None
pyarrow          : None
pytables         : None
s3fs             : None
scipy            : 1.3.3
sqlalchemy       : None
tables           : None
xarray           : None
xlrd             : 1.2.0
xlwt             : None
xlsxwriter       : None
@TomAugspurger
Copy link
Contributor

Is this likely an issue pandas or with openpyxl?

@mhooreman
Copy link
Author

Thanks @TomAugspurger
It’s a very good question, which I was not able to reply to. Sorry

@jbrockmendel
Copy link
Member

This is an openpyxl issue, xref #29862

@jbrockmendel jbrockmendel added the IO Excel read_excel, to_excel label Dec 11, 2019
@WillAyd
Copy link
Member

WillAyd commented Dec 11, 2019

Looks like that was fixed on openpyxl 3.0 branch yesterday - @mhooreman any chance you can install that version of openpyxl and see if it fixes the issue?

@mhooreman
Copy link
Author

mhooreman commented Dec 12, 2019

@WillAyd, installed pip's pandas and openpyxl from https://bitbucket.org/openpyxl/openpyxl/branch/3.0 on a dedicated venv.

It works. Thanks a lot.

Remark: in the bitbucket, openpyxl was still flagged 3.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO Excel read_excel, to_excel
Projects
None yet
Development

No branches or pull requests

4 participants