Skip to content

ENH: Change DatetimeIndex.time to also return timezone info #21865

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
wants to merge 8 commits into from
Closed

ENH: Change DatetimeIndex.time to also return timezone info #21865

wants to merge 8 commits into from

Conversation

jquinon
Copy link
Contributor

@jquinon jquinon commented Jul 11, 2018

Mainly just reverted changes from GH#21281 and updated docs. Also had to change one test added in GH#21281.

@pep8speaks
Copy link

pep8speaks commented Jul 11, 2018

Hello @jquinon! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on July 11, 2018 at 20:57 Hours UTC

@@ -84,7 +84,7 @@ Other Enhancements
- :meth:`Series.nlargest`, :meth:`Series.nsmallest`, :meth:`DataFrame.nlargest`, and :meth:`DataFrame.nsmallest` now accept the value ``"all"`` for the ``keep`` argument. This keeps all ties for the nth largest/smallest value (:issue:`16818`)
- :class:`IntervalIndex` has gained the :meth:`~IntervalIndex.set_closed` method to change the existing ``closed`` value (:issue:`21670`)
- :func:`~DataFrame.to_csv` and :func:`~DataFrame.to_json` now support ``compression='infer'`` to infer compression based on filename (:issue:`15008`)
-
- Changed DatetimeIndex.time to also return timezone information. (:issue:`21358)
Copy link
Member

Choose a reason for hiding this comment

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

Missing a closing backtick for the issue number. Can you also add an :attr: ref for DatetimeIndex.time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that look good?

@codecov
Copy link

codecov bot commented Jul 11, 2018

Codecov Report

Merging #21865 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21865      +/-   ##
==========================================
- Coverage   91.92%   91.92%   -0.01%     
==========================================
  Files         160      160              
  Lines       49906    49903       -3     
==========================================
- Hits        45875    45872       -3     
  Misses       4031     4031
Flag Coverage Δ
#multiple 90.3% <100%> (-0.01%) ⬇️
#single 42.11% <0%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/arrays/datetimes.py 95.79% <100%> (-0.06%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5d0daa0...b7e29cf. Read the comment docs.

@@ -577,15 +577,7 @@ def time(self):
"""
Returns numpy array of datetime.time. The time part of the Timestamps.
Copy link
Member

Choose a reason for hiding this comment

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

Could you expand this docstring to also mention that the datetime.time objects are in local time with associated timezone information.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that look good?

Copy link
Member

Choose a reason for hiding this comment

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

Small nit: could you replace , and contains with with. Otherwise LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem

@jreback jreback added Datetime Datetime data dtype API Design labels Jul 12, 2018
@jreback
Copy link
Contributor

jreback commented Jul 12, 2018

does the standard library preserve for datetime.datetime.time() ?

@mroeschke
Copy link
Member

.time() does not but .timetz() does:

In [12]: pytz.UTC.localize(datetime(2000, 1, 1)).time()
Out[12]: datetime.time(0, 0)

In [13]: pytz.UTC.localize(datetime(2000, 1, 1)).timetz()
Out[13]: datetime.time(0, 0, tzinfo=<UTC>)

I guess if we want to follow the standard library naming it should be naive, but I think its useful knowing in which timezone the local time resides.

An alternative is to depreciate the .time property for a time(tz=False) method that mirrors the standard library, has an option to return tz information and is maybe less API breaking.

Thoughts @jreback?

@jreback
Copy link
Contributor

jreback commented Jul 12, 2018

hmm its annoying that the std library does this with 2 methods, but I guess can't easily 'remove' a tz from a time (e.g. no .tz_localize(None).

@mroeschke
Copy link
Member

Yeah that's why I am more inclined to chose the method route to mimic the standard library but at least have a keyword argument (and not a second method) to include the tz in the output or not.

@jquinon
Copy link
Contributor Author

jquinon commented Jul 12, 2018

I can modify or cancel the PR as you guys see fit, just let me know when a decision is made!

@jorisvandenbossche
Copy link
Member

I would personally follow the standard library and leave it as is as a naive time.
You can always get the timezone separately if you want.

@jquinon jquinon closed this Jul 19, 2018
@jorisvandenbossche
Copy link
Member

@jquinon thanks for working on it anyhow!

@jquinon jquinon deleted the DatetimeIndex.time-timezoneinfo branch July 25, 2018 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Datetime Datetime data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Add timetz attribute to DatetimeIndex and Timestamp
7 participants