WIP: Add Alias expression.

This commit is contained in:
Scott Sanderson
2016-10-28 15:04:18 -04:00
committed by Joe Jevnik
parent 67b35168db
commit 13c8139d45
2 changed files with 42 additions and 1 deletions
+22 -1
View File
@@ -20,13 +20,14 @@ from numpy import (
rot90,
where,
)
from numpy.random import randn, seed
from numpy.random import randn, RandomState, seed
from zipline.errors import UnknownRankMethod
from zipline.lib.labelarray import LabelArray
from zipline.lib.rank import masked_rankdata_2d
from zipline.lib.normalize import naive_grouped_rowwise_apply as grouped_apply
from zipline.pipeline import Classifier, Factor, Filter
from zipline.pipeline.term import Alias
from zipline.pipeline.factors import (
Returns,
RSI,
@@ -1058,3 +1059,23 @@ class TestWindowSafety(TestCase):
self.assertFalse(F().demean().window_safe)
self.assertFalse(F(window_safe=False).demean().window_safe)
self.assertTrue(F(window_safe=True).demean().window_safe)
class TestAlias(BasePipelineTestCase):
def test_alias_factor(self):
f = F()
a = Alias(f)
f_values = RandomState(5).randn(5, 5)
self.check_terms(
terms={
'f_alias': a,
},
expected={
'f_alias': f_values,
},
initial_workspace={f: f_values},
mask=self.build_mask(ones((5, 5))),
)
+20
View File
@@ -696,6 +696,26 @@ class Slice(ComputableTerm):
)
class Alias(ComputableTerm):
"""An alias for another computed term."""
@expect_types(term=ComputableTerm)
def __new__(cls, term):
return super(Alias, cls).__new__(
cls,
window_length=0,
dtype=term.dtype,
missing_value=term.missing_value,
window_safe=term.window_safe,
ndim=term.ndim,
domain=term.domain,
inputs=(term,),
)
def _compute(self, inputs, dates, assets, mask):
return inputs[0]
def validate_dtype(termname, dtype, missing_value):
"""
Validate a `dtype` and `missing_value` passed to Term.__new__.