Skip to content

Add timetz attribute to DatetimeIndex #22132

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

Conversation

jquinon
Copy link
Contributor

@jquinon jquinon commented Jul 30, 2018

I only added timetz to DatetimeIndex because there was already a timetz method in Timestamp that did essentially the same thing. If it is still worth adding to Timestamp though, I can certainly do that.

@@ -180,6 +180,7 @@ Other Enhancements
- :func:`~DataFrame.to_csv` and :func:`~DataFrame.to_json` now support ``compression='infer'`` to infer compression based on filename (:issue:`15008`)
- :func:`to_timedelta` now supports iso-formated timedelta strings (:issue:`21877`)
- :class:`Series` and :class:`DataFrame` now support :class:`Iterable` in constructor (:issue:`2193`)
- :class:`DatetimeIndex` gained :attr:`~DatetimeIndex.timetz` attribute. Returns time with 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.

  1. I don't think you need the ~ before ~DatetimeIndex.timetz
  2. Can you clarify that this returns local time with timezone information

@pytest.mark.parametrize('tz', [
dateutil.tz.gettz('US/Eastern'), dateutil.tz.gettz('US/Pacific'),
dateutil.tz.gettz('UTC')])
def test_timetz_accessor(self, tz):
Copy link
Member

Choose a reason for hiding this comment

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

Instead could you use the tz_naive_fixture?

def tz_naive_fixture(request):

@mroeschke
Copy link
Member

Looks good overall!

  1. Could you add the timetz attribute to this list: http://pandas.pydata.org/pandas-docs/stable/timeseries.html?#time-date-components

  2. Could you check if we have some tests for Timestamp.timetz and add one if we don't have any?

@mroeschke mroeschke added Enhancement Timezones Timezone data dtype labels Jul 30, 2018
@jquinon
Copy link
Contributor Author

jquinon commented Jul 30, 2018

I didn't add a timetz attribute to Timestamp yet because it inherits a timetz method directly from standard library datetime. So should we add an attribute on top of that? And I assume we don't have any tests right now because it is a standard library thing

@mroeschke
Copy link
Member

I don't think you have to add a timetz property to Timestamp, but please go ahead and add some timetz tests for Timestamp if we don't have any so we can make sure the behavior is consistent with datetime.

@codecov
Copy link

codecov bot commented Jul 30, 2018

Codecov Report

Merging #22132 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #22132      +/-   ##
==========================================
+ Coverage   92.06%   92.06%   +<.01%     
==========================================
  Files         169      169              
  Lines       50694    50696       +2     
==========================================
+ Hits        46671    46673       +2     
  Misses       4023     4023
Flag Coverage Δ
#multiple 90.47% <100%> (ø) ⬆️
#single 42.32% <66.66%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/arrays/datetimes.py 95.52% <100%> (+0.02%) ⬆️
pandas/core/indexes/datetimes.py 95.54% <100%> (ø) ⬆️

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 776fed3...6cfa9a1. Read the comment docs.

@jquinon
Copy link
Contributor Author

jquinon commented Jul 30, 2018

Ok, gotcha

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

can we test for timetz on Timestamp (only in PY3 I think)?

@@ -1739,6 +1739,7 @@ Time/Date Components
DatetimeIndex.nanosecond
DatetimeIndex.date
DatetimeIndex.time
Copy link
Contributor

Choose a reason for hiding this comment

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

can add in the api section for Timestamp though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The timetz method was already there for Timestamp, and I added the property for DatetimeIndex

@mroeschke
Copy link
Member

Sorry forgot one more thing; could you add a timetz test for with the dt accessor (e.g. Series.dt.timetz)? They can be found here.

https://github.com/pandas-dev/pandas/blob/master/pandas/tests/series/test_datetime_values.py

After that one test LGTM.

@jreback
Copy link
Contributor

jreback commented Aug 2, 2018

I find an attribute for this is very confusing, as compared to the function call similar to .time(). would a function call be better here? (of course this would be a break with datetime.datetime)

@mroeschke
Copy link
Member

For the PR, I think we should leave it as a property for now since we break this property vs. method for other DatetimeIndex attributes (date, time, weekday), and then in another PR consider converting these to method calls (maybe even before v0.24).

(Although I don't even know why these are method calls for datetime in the first place...)

@jquinon
Copy link
Contributor Author

jquinon commented Aug 4, 2018

@mroeschke how does it look?

@mroeschke
Copy link
Member

Any other comments @jreback?

@jreback jreback added this to the 0.24.0 milestone Aug 9, 2018
@jreback jreback merged commit 475e391 into pandas-dev:master Aug 9, 2018
@jreback
Copy link
Contributor

jreback commented Aug 9, 2018

thanks @jquinon nice patch!

@jquinon jquinon deleted the Add_timetz_to_DatetimeIndex_and_Timestamp branch August 19, 2018 23:39
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Add timetz attribute to DatetimeIndex and Timestamp
4 participants