New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple outputs for custom factors #1119
Conversation
@@ -510,6 +520,42 @@ def test_rolling_and_nonrolling(self): | |||
), | |||
) | |||
|
|||
def test_factor_with_multiple_outputs(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Add better test cases
ebf033a
to
3fc69c1
Compare
|
||
def compute(self, today, assets, out, open, close): | ||
out.double_open[:] = open * 2 | ||
out.double_close[:] = close * 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice API!
enough outputs and that factor does not have class-level default outputs. | ||
""" | ||
msg = ( | ||
"{termname} requires at least two outputs, but was given " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"at least two" seems more specific than this should be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes; I'll make RecarrayFactor support single outputs as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually meant that this might want to be at least {N}
, where N is an arg, but I don't know if there are cases where we know we need more than two outputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok. So for the purpose of RecarrayFactors as we have them it makes sense, but wouldn't hurt to be more generalizable in case we come across such a case.
4596d90
to
9fce2f8
Compare
def _validate(self): | ||
super(RecarrayFactor, self)._validate() | ||
if not self.outputs: | ||
raise TermOutputsNotSpecified(termname=type(self).__name__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In thinking about it, I don't think a RecarrayFactor even needs to specify any outputs. At the end of the day it acts how all other regular factors do with a single out. So this can all be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this check should be performed on the inputted factor, i.e. check that the parent's factor.outputs
is not empty.
class MultipleOutputs(CustomFactor): | ||
window_length = 1 | ||
inputs = [USEquityPricing.open, USEquityPricing.close] | ||
outputs = ['open', 'close'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want a test that exercises the behavior of passing outputs
dynamically to the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in test_custom_factor_outputs_parameter
@ssanderson Should be ready for another look |
''' | ||
dtype = float64_dtype | ||
|
||
def __getattr__(self, attribute_name): | ||
if self.outputs is NotSpecified: | ||
raise AttributeError() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be AttributeError(attribute_name)
.
0eb4d12
to
ec68d04
Compare
ec68d04
to
c4d190c
Compare
c4d190c
to
d9bfcaa
Compare
LGTM. @dmichalowicz feel free to merge when appveyor finishes. |
Add an optional
outputs
parameter to CustomFactor allowing multiple outputs to be computed and returned from a single CustomFactor, each output of which is itself a Factor.