From 17c20da0264bf31656fc963dd0034d6a1bb7445f Mon Sep 17 00:00:00 2001 From: Stewart Douglas Date: Wed, 25 May 2016 15:04:11 -0400 Subject: [PATCH 1/2] TST: Add test to append minutely data --- tests/data/test_minute_bars.py | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/data/test_minute_bars.py b/tests/data/test_minute_bars.py index 8bde26a6..8d304e6a 100644 --- a/tests/data/test_minute_bars.py +++ b/tests/data/test_minute_bars.py @@ -373,6 +373,47 @@ class BcolzMinuteBarTestCase(TestCase): volume_price = self.reader.get_value(sid, second_minute, 'volume') self.assertEquals(10.0, volume_price) + def test_append_on_new_day(self): + sid = 1 + + ohlcv = { + 'open': [2.0], + 'high': [3.0], + 'low': [1.0], + 'close': [2.0], + 'volume': [10.0] + } + + first_minute = self.market_opens[TEST_CALENDAR_START] + data = DataFrame( + data=ohlcv, + index=[first_minute]) + self.writer.write_sid(sid, data) + + next_day_minute = first_minute + Timedelta(days=1) + new_data = DataFrame( + data=ohlcv, + index=[next_day_minute]) + self.writer.write_sid(sid, new_data) + + second_minute = first_minute + Timedelta(minutes=1) + + # The second minute should have been padded with zeros + for col in ('open', 'high', 'low', 'close'): + assert_almost_equal( + nan, self.reader.get_value(sid, second_minute, col) + ) + self.assertEqual( + 0, self.reader.get_value(sid, second_minute, 'volume') + ) + + # The first day should contain US_EQUITIES_MINUTES_PER_DAY rows. + # The second day should contain a single row. + self.assertEqual( + len(self.writer._ensure_ctable(sid)), + US_EQUITIES_MINUTES_PER_DAY + 1, + ) + def test_write_multiple_sids(self): """ Test writing multiple sids. From 71bcc7f9112b61e8541f2c71b27e26163ebf25f3 Mon Sep 17 00:00:00 2001 From: Stewart Douglas Date: Wed, 25 May 2016 16:10:36 -0400 Subject: [PATCH 2/2] DOC: Update comments to reflect new behavior --- zipline/data/minute_bars.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/zipline/data/minute_bars.py b/zipline/data/minute_bars.py index 2bb89df3..2cedd1b2 100644 --- a/zipline/data/minute_bars.py +++ b/zipline/data/minute_bars.py @@ -408,9 +408,10 @@ class BcolzMinuteBarWriter(object): """ Fill sid container with empty data through the specified date. - e.g. if the date is two days after the last date in the sid's existing - output, 2 x `minute_per_day` worth of zeros will be added to the - output. + If the last recorded trade is not at the close, then that day will be + padded with zeros until its close. Any day after that (up to and + including the specified date) will be padded with `minute_per_day` + worth of zeros Parameters: ----------- @@ -490,7 +491,7 @@ class BcolzMinuteBarWriter(object): If there is no bcolz ctable yet created for the sid, create it. If the length of the bcolz ctable is not exactly to the date before the first day provided, fill the ctable with 0s up to that date. - Writes in blocks of the size of the days times minutes per day. + Parameters: ----------- sid : int @@ -523,7 +524,7 @@ class BcolzMinuteBarWriter(object): If there is no bcolz ctable yet created for the sid, create it. If the length of the bcolz ctable is not exactly to the date before the first day provided, fill the ctable with 0s up to that date. - Writes in blocks of the size of the days times minutes per day. + Parameters: ----------- sid : int