From 765f9b6d5777de15924ac3e451c39f785a37b1af Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Fri, 12 Aug 2016 14:03:15 -0400 Subject: [PATCH] MAINT: Improve/test errors for insufficient data. --- tests/pipeline/test_engine.py | 23 +++++++++++++++++++++++ zipline/pipeline/engine.py | 8 ++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/tests/pipeline/test_engine.py b/tests/pipeline/test_engine.py index 0521174b..0e2d2197 100644 --- a/tests/pipeline/test_engine.py +++ b/tests/pipeline/test_engine.py @@ -206,6 +206,29 @@ class ConstantInputTestCase(WithTradingEnvironment, ZiplineTestCase): with self.assertRaisesRegexp(ValueError, msg): engine.run_pipeline(p, self.dates[2], self.dates[1]) + def test_fail_usefully_on_insufficient_data(self): + loader = self.loader + engine = SimplePipelineEngine( + lambda column: loader, self.dates, self.asset_finder, + ) + + class SomeFactor(CustomFactor): + inputs = [USEquityPricing.close] + window_length = 10 + + def compute(self, today, assets, out, closes): + pass + + p = Pipeline(columns={'t': SomeFactor()}) + + # self.dates[9] is the earliest date we should be able to compute. + engine.run_pipeline(p, self.dates[9], self.dates[9]) + + # We shouldn't be able to compute dates[8], since we only know about 8 + # prior dates, and we need a window length of 10. + with self.assertRaises(NoFurtherDataError) as e: + engine.run_pipeline(p, self.dates[8], self.dates[8]) + def test_same_day_pipeline(self): loader = self.loader engine = SimplePipelineEngine( diff --git a/zipline/pipeline/engine.py b/zipline/pipeline/engine.py index 8be01f4e..ffb5b1c9 100644 --- a/zipline/pipeline/engine.py +++ b/zipline/pipeline/engine.py @@ -211,10 +211,10 @@ class SimplePipelineEngine(object): start_idx, end_idx = self._calendar.slice_locs(start_date, end_date) if start_idx < extra_rows: raise NoFurtherDataError( - msg="Insufficient data to compute Pipeline mask: " - "start date was %s, " - "earliest known date was %s, " - "and %d extra rows were requested." % ( + msg="Insufficient data to compute Pipeline.\n\n" + "start date was %s\n" + "earliest known date was %s\n" + "%d extra rows were required" % ( start_date, calendar[0], extra_rows, ), )