-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: clarify (un)aware logic in tz_localize() docstring #40940
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
pandas/core/arrays/datetimes.py
Outdated
Time zone localization helps to switch from time zone aware to time | ||
zone unaware objects. | ||
Time zone localization helps to switch from time zone unaware to time | ||
zone aware objects. |
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.
the tz is None the existing is correct - why don't we break this down into multiple statements
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.
Hey @jreback thank you for super quick feedback! Let's clarify.
I was considering to remove the entire sentence, because the two sentences above the one I changed already say pretty precisely what's happening:
Localize tz-naive Datetime Array/Index to tz-aware Datetime Array/Index.
This method takes a time zone (tz) naive Datetime Array/Index object and makes this time zone aware.
This third sentence says the opposite:
Time zone localization helps to switch from time zone aware to time zone unaware objects.
The way I understand things the first two sentences are correct, the third one is not.
This assumes that "tz-naive" means the same as "tz-unaware" or just "unaware" which I think we agree on, do we? :)
Maybe I miss something, would love to understand what you mean with "tz is None".
Also, the way I have personally always looked at methods like this is:
- simply attach time zone information (add meta data)
- leave the actual numbers intact (no magic shifting / translation)
That's what tz_localize() is doing according to the code examples. It's therefore a useful helper tool to switch from tz-unaware to tz-aware objects (which is the opposite of what's written in the sentenced I proposed modifying).
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.
I think this sentence tries to (poorly) describe that tz_localize(None)
can convert tz-aware to tz-unaware (there's an example in this doc-string already)
So it would be great to have this in a new paragraph clarifying this point.
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.
Oooooh. Gotcha. And now I understand that "the tz is None the existing is correct" was supposed to be
if
tz
isNone
, ...
🙏
I'll happily improve on the current patch. Thanks everyone.
Pushed another commit, PTAL @mroeschke! |
thanks @jgehrcke |
A simple hopefully no-brainer documentation patch; came across this while reading https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DatetimeIndex.tz_localize.html#pandas-datetimeindex-tz-localize.