Skip to content

Commit

Permalink
Merge pull request #1981 from quantopian/no-further-data-error-constr…
Browse files Browse the repository at this point in the history
…uction

BUG: Fixed construction of NoFurtherDataError
  • Loading branch information
richafrank committed Oct 11, 2017
2 parents 5c0e19b + cdca50d commit bcdafb9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
31 changes: 29 additions & 2 deletions tests/pipeline/test_downsampling.py
Expand Up @@ -6,6 +6,7 @@
import pandas as pd
from pandas.util.testing import assert_frame_equal

from zipline.errors import NoFurtherDataError
from zipline.pipeline import (
Pipeline,
CustomFactor,
Expand Down Expand Up @@ -48,7 +49,7 @@ def compute(self, today, assets, out, cats):
out[:] = cats[0]


class ComputeExtraRowsTestcase(WithTradingSessions, ZiplineTestCase):
class ComputeExtraRowsTestCase(WithTradingSessions, ZiplineTestCase):

DATA_MIN_DAY = pd.Timestamp('2012-06', tz='UTC')
DATA_MAX_DAY = pd.Timestamp('2015', tz='UTC')
Expand Down Expand Up @@ -165,7 +166,7 @@ def test_yearly(self, base_terms, calendar_name):
# Simulate requesting computation where the unaltered lookback would
# land on the last date of 2012. The downsampled terms should request
# enough extra rows to push us back to the first known date, which is
# in the middle of 2012
# in the middle of 2012.
for i in range(0, 30, 5):
start_session = sessions_in_2013[i]
self.check_extra_row_calculations(
Expand All @@ -185,6 +186,32 @@ def test_yearly(self, base_terms, calendar_name):
expected_extra_rows=i + 1,
)

# Simulate requesting computation where the unaltered lookback would
# land prior to the first date of 2012. The downsampled terms will fail
# to request enough extra rows.
for i in range(0, 30, 5):
with self.assertRaisesRegexp(
NoFurtherDataError,
'\s*Insufficient data to compute Pipeline'
):
self.check_extra_row_calculations(
downsampled_terms,
all_sessions,
all_sessions[i],
end_session,
min_extra_rows=i + 1,
expected_extra_rows=i + 1,
)

self.check_extra_row_calculations(
base_terms,
all_sessions,
all_sessions[i],
end_session,
min_extra_rows=i + 1,
expected_extra_rows=i + 1,
)

@parameter_space(
calendar_name=TRADING_CALENDAR_STRS,
base_terms=[
Expand Down
2 changes: 1 addition & 1 deletion zipline/pipeline/mixins.py
Expand Up @@ -391,7 +391,7 @@ def compute_extra_rows(self,
try:
current_start_pos = all_dates.get_loc(start_date) - min_extra_rows
if current_start_pos < 0:
raise NoFurtherDataError(
raise NoFurtherDataError.from_lookback_window(
initial_message="Insufficient data to compute Pipeline:",
first_date=all_dates[0],
lookback_start=start_date,
Expand Down

0 comments on commit bcdafb9

Please sign in to comment.