mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-19 11:22:06 +08:00
WIP: Add Alias expression.
This commit is contained in:
committed by
Joe Jevnik
parent
67b35168db
commit
13c8139d45
@@ -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))),
|
||||
)
|
||||
|
||||
@@ -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__.
|
||||
|
||||
Reference in New Issue
Block a user