Skip to content

ERR: Raise error in to_excel when saving datetimes with timezones #27129

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

Merged
merged 5 commits into from
Jun 29, 2019

Conversation

mroeschke
Copy link
Member

Raise a consistent error, regardless of the writing engine, when saving datetimes with timezones in Excel since they are unsupported.

@mroeschke
Copy link
Member Author

cc @WillAyd

@mroeschke mroeschke added Error Reporting Incorrect or improved errors from pandas IO Excel read_excel, to_excel Timezones Timezone data dtype labels Jun 29, 2019
@mroeschke mroeschke added this to the 0.25.0 milestone Jun 29, 2019
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comment otherwise lgtm

data = pd.Timestamp('2019', tz=tz)
df = DataFrame([data], dtype=dtype)
with pytest.raises(ValueError, match="Excel does not support"):
df.to_excel(self.path, engine=engine)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call this without the engine argument - it's already set during test setup so this would be duplicative

That entire mechanism needs a refactor but separate exercise for #27096

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@@ -402,6 +402,10 @@ def _format_value(self, val):
val = '-{inf}'.format(inf=self.inf_rep)
elif self.float_format is not None:
val = float(self.float_format % val)
if getattr(val, 'tzinfo', None) is not None:
raise ValueError('Excel does not support datetimes with timzones. '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small typo here for timezones if you want to fix locally (otherwise can do before merge)

@pep8speaks
Copy link

pep8speaks commented Jun 29, 2019

Hello @mroeschke! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-06-29 17:08:50 UTC

@mroeschke mroeschke merged commit 2811464 into pandas-dev:master Jun 29, 2019
@mroeschke mroeschke deleted the excel_timezone_raise branch June 29, 2019 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas IO Excel read_excel, to_excel Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

to_excel Mishandles Mixing of tz-aware datetimes to_excel can't handle index with time zones
3 participants