Skip to content

to_excel() TyperError: Unsupported type <class 'pandas._libs.tslibs.period.Period'> in write() #26999

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
riptusk331 opened this issue Jun 22, 2019 · 4 comments · Fixed by #27006
Labels
IO Excel read_excel, to_excel Period Period data type
Milestone

Comments

@riptusk331
Copy link
Contributor

riptusk331 commented Jun 22, 2019

Code Sample, a copy-pastable example if possible

writer = pd.ExcelWriter(Path().resolve() / 'output' / 'out.xlsx')
for dftup in exportlist:
    dftup[0].to_excel(writer, sheet_name=dftup[2])

Problem description

Note that a similar issue was covered in in #19242, but with a different data type.
The above code takes a list of tuples which contain the DataFrames (in position 0) and the desired sheet names (in position 2) I would like to write. These DataFrames have MultiIndex columns whose levels are type PeriodIndex. The first level is an index of yearly Periods (freq='Y') and the second level an index of Quarterly periods (freq='Q').

When I try to write the DataFrames to excel, I get the following error (I can post the whole trace if needed). Any ideas?

TypeError: Unsupported type <class 'pandas._libs.tslibs.period.Period'> in write()

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.7.3.final.0
python-bits: 64
OS: Darwin
OS-release: 18.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.2
pytest: 4.5.0
pip: 19.1.1
setuptools: 41.0.1
Cython: 0.29.8
numpy: 1.16.4
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 7.5.0
sphinx: 2.0.1
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: 1.2.1
tables: 3.5.1
numexpr: 2.6.9
feather: None
matplotlib: 3.0.3
openpyxl: 2.6.2
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.8
lxml.etree: 4.3.3
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: 1.3.3
pymysql: None
psycopg2: 2.7.6.1 (dt dec pq3 ext lo64)
jinja2: 2.10.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

@WillAyd
Copy link
Member

WillAyd commented Jun 22, 2019

If you take a look at #19244 could probably extend that to make sure this is supported. Want to try a PR?

@WillAyd WillAyd added IO Excel read_excel, to_excel Period Period data type labels Jun 22, 2019
@WillAyd WillAyd added this to the Contributions Welcome milestone Jun 22, 2019
@riptusk331
Copy link
Contributor Author

Sure thing - I'll have a look and create a PR.

@riptusk331
Copy link
Contributor Author

Ok so I have identified the source of the bug - but I have a question before I do a PR. It looks like the Excel IO has been changed a bit on the master branch from what the current stable 0.24.2 release is. I know where to make the change in both versions, but am not sure which I should push.

Thanks

@jreback
Copy link
Contributor

jreback commented Jun 23, 2019

only PR to master

@jreback jreback modified the milestones: Contributions Welcome, 0.25.0 Jun 27, 2019
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 Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants