From a64a1ee6191a2e2309fddab3f2852709331fb5be Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Mon, 2 Mar 2015 11:02:13 -0500 Subject: [PATCH] TST: Use pandas relativedelta for calendar end to account for leap year. Some unit tests for test_tradingcalendar failed on 2015-03-01, because the addition of 365 days put the end date at 2016-02-29; when the replaces the year on that date it fails because there is no 2017-02-29. Instead use relativedelta with a year argument which accounts for leap years. Fixes the following test failure: ``` ====================================================================== ERROR: test_day_after_thanksgiving (tests.test_tradingcalendar.TestTradingCalendar) ---------------------------------------------------------------------- Traceback (most recent call last): File "./tests/test_tradingcalendar.py", line 211, in test_day_after_thanksgiving tradingcalendar.end.replace(year=tradingcalendar.end.year + 1) File "tslib.pyx", line 297, in pandas.tslib.Timestamp.replace (pandas/tslib.c:7325) ValueError: day is out of range for month ---------------------------------------------------------------------- Ran 1 test in 0.001s ``` --- zipline/utils/tradingcalendar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zipline/utils/tradingcalendar.py b/zipline/utils/tradingcalendar.py index 552566a3..2c3db622 100644 --- a/zipline/utils/tradingcalendar.py +++ b/zipline/utils/tradingcalendar.py @@ -23,7 +23,7 @@ start = pd.Timestamp('1990-01-01', tz='UTC') end_base = pd.Timestamp('today', tz='UTC') # Give an aggressive buffer for logic that needs to use the next trading # day or minute. -end = end_base + timedelta(days=365) +end = end_base + pd.datetools.relativedelta(years=1) def canonicalize_datetime(dt):