From 64f991b400e44fa0085cf0edb37ea3a086b878c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20S=C3=A1nchez=20de=20Le=C3=B3n=20Peque?= Date: Thu, 18 May 2017 18:31:05 +0200 Subject: [PATCH] Fix bug in TradingCalendar initialization A TypeError exception was raised with message "Cannot join tz-naive with tz-aware DatetimeIndex". Removing old unnecessary workaround in `holidays_at_time` function (Pandas already fixed that before 0.18) fixes this issue. --- tests/calendars/test_nyse_calendar.py | 14 ++++++++++++++ zipline/utils/calendars/trading_calendar.py | 6 +----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/calendars/test_nyse_calendar.py b/tests/calendars/test_nyse_calendar.py index fcaedc78..26bd879c 100644 --- a/tests/calendars/test_nyse_calendar.py +++ b/tests/calendars/test_nyse_calendar.py @@ -226,3 +226,17 @@ class NYSECalendarTestCase(ExchangeCalendarTestBase, TestCase): self.assertFalse(self.calendar.is_open_on_minute(wednesday_before)) self.assertTrue(self.calendar.is_open_on_minute(friday_after_open)) self.assertTrue(self.calendar.is_open_on_minute(friday_after)) + + +class CalendarStartEndTestCase(TestCase): + def test_start_end(self): + """ + Check TradingCalendar with defined start/end dates. + """ + start = pd.Timestamp('2010-1-3', tz='UTC') + end = pd.Timestamp('2010-1-10', tz='UTC') + calendar = NYSEExchangeCalendar(start=start, end=end) + expected_first = pd.Timestamp('2010-1-4', tz='UTC') + expected_last = pd.Timestamp('2010-1-8', tz='UTC') + self.assertTrue(calendar.first_trading_session == expected_first) + self.assertTrue(calendar.last_trading_session == expected_last) diff --git a/zipline/utils/calendars/trading_calendar.py b/zipline/utils/calendars/trading_calendar.py index 9a09c566..2de92e27 100644 --- a/zipline/utils/calendars/trading_calendar.py +++ b/zipline/utils/calendars/trading_calendar.py @@ -889,11 +889,7 @@ def days_at_time(days, t, tz, day_offset=0): def holidays_at_time(calendar, start, end, time, tz): return days_at_time( - calendar.holidays( - # Workaround for https://github.com/pydata/pandas/issues/9825. - start.tz_localize(None), - end.tz_localize(None), - ), + calendar.holidays(start, end), time, tz=tz, )