BUG: days_at_time should return UTC dates.

Adds an example and clarifies the docs.
This commit is contained in:
Scott Sanderson
2016-09-29 11:31:19 -04:00
committed by Andrew Liang
parent 87daa75c0c
commit d5ea9c4daa
+21 -6
View File
@@ -809,20 +809,35 @@ class TradingCalendar(with_metaclass(ABCMeta)):
def days_at_time(days, t, tz, day_offset=0):
"""
Shift an index of days to time t, interpreted in tz.
Create an index of days at time ``t``, interpreted in timezone ``tz``.
Overwrites any existing tz info on the input.
The returned index is localized to UTC.
Parameters
----------
days : DatetimeIndex
The "base" time which we want to change.
An index of dates (represented as midnight).
t : datetime.time
The time we want to offset @days by
The time to apply as an offset to each day in ``days``.
tz : pytz.timezone
The timezone which these times represent
The timezone to use to interpret ``tz``.
day_offset : int
The number of days we want to offset @days by
Example
-------
In the example below, the times switch from 13:45 to 12:45 UTC because
March 13th is the daylight savings transition for US/Eastern. All the
times are still 8:45 when interpreted in US/Eastern.
>>> import pandas as pd; import datetime; import pprint
>>> dts = pd.date_range('2016-03-12', '2016-03-14')
>>> dts_at_845 = days_at_time(dts, datetime.time(8, 45), 'US/Eastern')
>>> pprint.pprint([str(dt) for dt in dts_at_845])
['2016-03-12 13:45:00+00:00',
'2016-03-13 12:45:00+00:00',
'2016-03-14 12:45:00+00:00']
"""
if len(days) == 0:
return days
@@ -835,7 +850,7 @@ def days_at_time(days, t, tz, day_offset=0):
minutes=t.minute,
seconds=t.second,
)
return (days + delta).tz_localize(tz)
return (days + delta).tz_localize(tz).tz_convert('UTC')
def holidays_at_time(calendar, start, end, time, tz):