mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-01 09:42:50 +08:00
MAINT: Use Timedelta instead of DateOffset.
In days_at_time, use a Timedelta instead of a DateOffset. We were previously using DateOffset to work around a pandas 16 bug even though it raises a PerformanceWarning. Now that we're on pandas 18, we can use the much simpler Timedelta construction.
This commit is contained in:
committed by
Andrew Liang
parent
d47144dfb8
commit
87daa75c0c
@@ -25,7 +25,6 @@ from pandas import (
|
||||
DataFrame,
|
||||
date_range,
|
||||
DatetimeIndex,
|
||||
DateOffset
|
||||
)
|
||||
from pandas.tseries.offsets import CustomBusinessDay
|
||||
from zipline.utils.calendars._calendar_helpers import (
|
||||
@@ -830,16 +829,13 @@ def days_at_time(days, t, tz, day_offset=0):
|
||||
|
||||
# Offset days without tz to avoid timezone issues.
|
||||
days = DatetimeIndex(days).tz_localize(None)
|
||||
days_offset = days + DateOffset(days=day_offset)
|
||||
|
||||
# Shift all days to the target time in the local timezone, then
|
||||
# convert to UTC.
|
||||
|
||||
# FIXME: Once we're off Pandas 16, see if we can replace DateOffset with
|
||||
# TimeDelta.
|
||||
return days_offset.shift(
|
||||
1, freq=DateOffset(hour=t.hour, minute=t.minute, second=t.second)
|
||||
).tz_localize(tz).tz_convert('UTC')
|
||||
delta = pd.Timedelta(
|
||||
days=day_offset,
|
||||
hours=t.hour,
|
||||
minutes=t.minute,
|
||||
seconds=t.second,
|
||||
)
|
||||
return (days + delta).tz_localize(tz)
|
||||
|
||||
|
||||
def holidays_at_time(calendar, start, end, time, tz):
|
||||
|
||||
Reference in New Issue
Block a user