mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-30 10:13:05 +08:00
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
```
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user