Skip to content

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

Merged
merged 2 commits into from
Apr 16, 2021

Conversation

jgehrcke
Copy link
Contributor

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.
Copy link
Contributor

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

Copy link
Contributor Author

@jgehrcke jgehrcke Apr 14, 2021

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).

Copy link
Member

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.

Copy link
Contributor Author

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 is None, ...

🙏

I'll happily improve on the current patch. Thanks everyone.

@jgehrcke jgehrcke changed the title DOC: fix tz (un)aware logic in tz_localize() docstring DOC: clarify (un)aware logic in tz_localize() docstring Apr 16, 2021
@jgehrcke
Copy link
Contributor Author

Pushed another commit, PTAL @mroeschke!

@mroeschke mroeschke added the Docs label Apr 16, 2021
@mroeschke mroeschke added this to the 1.3 milestone Apr 16, 2021
@jreback jreback merged commit a89cba8 into pandas-dev:master Apr 16, 2021
@jreback
Copy link
Contributor

jreback commented Apr 16, 2021

thanks @jgehrcke

yeshsurya pushed a commit to yeshsurya/pandas that referenced this pull request Apr 21, 2021
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants