Skip to content

Commit

Permalink
Test dates fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichalowicz committed Jun 21, 2016
1 parent 63a1155 commit ef19275
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions tests/pipeline/test_slice.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
"""
Tests for slicing pipeline terms.
"""
from pandas import (
date_range,
Int64Index,
Timestamp,
)
from pandas import Int64Index, Timestamp
from pandas.util.testing import assert_frame_equal

from zipline.assets import Asset
Expand Down Expand Up @@ -47,12 +43,13 @@ class SliceTestCase(WithSeededRandomPipelineEngine, ZiplineTestCase):
def init_class_fixtures(cls):
super(SliceTestCase, cls).init_class_fixtures()

day = cls.trading_schedule.day
cls.dates = dates = date_range(
'2015-02-01', '2015-02-28', freq=day, tz='UTC',
)
cls.start_date = dates[14]
cls.end_date = dates[18]
# Using the date at index 14 as the start date because when running
# pipelines, especially those involving correlations or regressions, we
# want to make sure there are enough days to look back on. The end date
# at index 18 is chosen for convenience, as it makes for a contiguous
# five day span.
cls.pipeline_start_date = cls.trading_days[14]
cls.pipeline_end_date = cls.trading_days[18]

# Random input for factors.
cls.col = TestingDataSet.float_col
Expand Down Expand Up @@ -85,8 +82,8 @@ def compute(self, today, assets, out, returns, returns_slice):
# function of our custom factor above.
self.run_pipeline(
Pipeline(columns={'uses_sliced_input': UsesSlicedInput()}),
self.start_date,
self.end_date,
self.pipeline_start_date,
self.pipeline_end_date,
)

@parameter_space(unmasked_column=[0, 1, 2], slice_column=[0, 1, 2])
Expand All @@ -97,8 +94,8 @@ def test_slice_with_masking(self, unmasked_column, slice_column):
"""
sids = self.sids
asset_finder = self.asset_finder
start_date = self.start_date
end_date = self.end_date
start_date = self.pipeline_start_date
end_date = self.pipeline_end_date

# Create a filter that masks out all but a single asset.
unmasked_asset = asset_finder.retrieve_asset(sids[unmasked_column])
Expand Down Expand Up @@ -180,8 +177,8 @@ def compute(self, today, assets, out, returns_slice):
with self.assertRaises(NonExistentAssetInTimeFrame):
self.run_pipeline(
Pipeline(columns={'uses_sliced_input': UsesSlicedInput()}),
self.start_date,
self.end_date,
self.pipeline_start_date,
self.pipeline_end_date,
)

def test_window_safety_of_slices(self):
Expand All @@ -206,8 +203,8 @@ def compute(self, today, assets, out, sma_slice):
with self.assertRaises(NonWindowSafeInput):
self.run_pipeline(
Pipeline(columns={'uses_sliced_input': UsesSlicedInput()}),
self.start_date,
self.end_date,
self.pipeline_start_date,
self.pipeline_end_date,
)

# Make sure that slices of custom factors are not window safe.
Expand All @@ -231,8 +228,8 @@ def compute(self, today, assets, out, my_unsafe_factor_slice):
with self.assertRaises(NonWindowSafeInput):
self.run_pipeline(
Pipeline(columns={'uses_sliced_input': UsesSlicedInput()}),
self.start_date,
self.end_date,
self.pipeline_start_date,
self.pipeline_end_date,
)

# Create a window safe factor.
Expand Down Expand Up @@ -306,7 +303,9 @@ def test_factor_correlation_methods(self,
}

results = self.run_pipeline(
Pipeline(columns=columns), self.start_date, self.end_date,
Pipeline(columns=columns),
self.pipeline_start_date,
self.pipeline_end_date,
)
pearson_results = results['pearson'].unstack()
spearman_results = results['spearman'].unstack()
Expand Down Expand Up @@ -382,7 +381,9 @@ def test_factor_regression_method(self, returns_length, regression_length):
}

results = self.run_pipeline(
Pipeline(columns=columns), self.start_date, self.end_date,
Pipeline(columns=columns),
self.pipeline_start_date,
self.pipeline_end_date,
)
regression_results = results['regression'].unstack()
expected_regression_results = results['expected_regression'].unstack()
Expand Down

0 comments on commit ef19275

Please sign in to comment.