Skip to content

to_excel doesn't support dateutil.relativedelta #9372

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
s-celles opened this issue Jan 29, 2015 · 6 comments
Closed

to_excel doesn't support dateutil.relativedelta #9372

s-celles opened this issue Jan 29, 2015 · 6 comments
Labels
IO Excel read_excel, to_excel

Comments

@s-celles
Copy link
Contributor

Hello,

to_excel doesn't support dateutil.relativedelta

import pandas as pd
from dateutil.relativedelta import relativedelta
df = pd.DataFrame([relativedelta(years=2)])
df.to_excel('out.xls')

raises Exception: Unexpected data type <type 'instance'>

df.to_excel('out.xlsx')

raises AttributeError: relativedelta instance has no attribute '__float__'

Not sure if it's a Pandas issue, an XLS writer issue or a dateutil issue.

@jorisvandenbossche
Copy link
Member

What do you expect as the result in excel, as I think excel does not have such a datatype? A string representation?

@s-celles
Copy link
Contributor Author

to_csv returns a string so it could be a string also

@jorisvandenbossche
Copy link
Member

Related to #8188 (same question, but for lists). There is a PR for that (#9181, although that will not solve this case)

@s-celles
Copy link
Contributor Author

Maybe by default to_excel should raise an error when type is not "known" but an additional flag could be add to save to string (using __str__ or __repr__ ?).

@TomAugspurger TomAugspurger added this to the Next Major Release milestone Jul 8, 2017
@WillAyd
Copy link
Member

WillAyd commented Jan 21, 2019

I can't reproduce this. issue on master; if you are still seeing feel free to ping and can reopen

@s-celles
Copy link
Contributor Author

s-celles commented Jan 21, 2019

Thanks. I haven't try this feature recently.

Here is Excel content (both out.xls and out.xlsx):

  0
0 relativedelta(years=+2)

It's better than raising an exception.

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