STY: style changes and strictly_true_filter

This commit is contained in:
Gil Wassermann
2016-08-01 11:16:02 -04:00
parent 2d5a2055d0
commit 73de8e6182
3 changed files with 9 additions and 11 deletions
+5 -5
View File
@@ -395,8 +395,8 @@ class FilterTestCase(BasePipelineTestCase):
)
check_arrays(results['isfinite'], isfinite(data))
def test_smoothing_filter(self):
from zipline.pipeline.filters import SmoothingFilter
def test_strictly_true_filter(self):
from zipline.pipeline.filters import StrictlyTrueFilter
data = full(self.default_shape, True, dtype=bool)
# one column all false
@@ -407,13 +407,13 @@ class FilterTestCase(BasePipelineTestCase):
inputs = ()
window_length = 0
smoothing_filter = SmoothingFilter(
strictly_true_filter = StrictlyTrueFilter(
inputs=[InputFilter()],
window_length=self.default_shape[0]
)
results = self.run_graph(
TermGraph({'smoothing': smoothing_filter}),
TermGraph({'Filter': strictly_true_filter}),
initial_workspace={InputFilter(): data}
)
@@ -421,7 +421,7 @@ class FilterTestCase(BasePipelineTestCase):
expected_result[0] = False
expected_result[1] = False
check_arrays(
results['smoothing'].flatten(),
results['Filter'].flatten(),
expected_result,
)
+2 -2
View File
@@ -8,7 +8,7 @@ from .filter import (
NumExprFilter,
PercentileFilter,
SingleAsset,
SmoothingFilter,
StrictlyTrueFilter,
)
__all__ = [
@@ -21,5 +21,5 @@ __all__ = [
'NumExprFilter',
'PercentileFilter',
'SingleAsset',
'SmoothingFilter',
'StrictlyTrueFilter',
]
+2 -4
View File
@@ -8,7 +8,6 @@ from numpy import (
float64,
nan,
nanpercentile,
sum as sum_
)
from zipline.errors import (
@@ -491,11 +490,10 @@ class SingleAsset(Filter):
return out
class SmoothingFilter(CustomFilter):
class StrictlyTrueFilter(CustomFilter):
"""
A Filter that requires its inputs to have
been True for the last `window_length` days.
An integral part of the Q500US methodology
**Default Inputs**: None
@@ -503,4 +501,4 @@ class SmoothingFilter(CustomFilter):
"""
def compute(self, today, assets, out, arg):
out[:] = (sum_(arg, axis=0) == self.window_length)
out[:] = (sum(arg) == self.window_length)