-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
cc @WillAyd |
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
pandas/io/formats/excel.py
Outdated
@@ -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. ' |
There was a problem hiding this comment.
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)
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 |
git diff upstream/master -u -- "*.py" | flake8 --diff
Raise a consistent error, regardless of the writing engine, when saving datetimes with timezones in Excel since they are unsupported.