-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
BUG: cal attribute of aggregate rules was not being propagated #2062
Conversation
Just to make sure I understand, |
Yup, semantically there's no reason there for the second term; this was just to show that each of those terms doesn't get assigned a |
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.
Had a few small comments, but generally looks good. My general preference would be to not mutate these objects at all after construction, but doing that without breaking the user-facing API would mean we'd have to do something like make the user-facing objects into factories that construct "real" rules given a calendar, which feels enough more complicated that I'm not even sure I'd prefer that here if it were zero extra work to implement.
zipline/algorithm.py
Outdated
@@ -1063,7 +1063,7 @@ def fetch_csv(self, | |||
|
|||
return csv_data_source | |||
|
|||
def add_event(self, rule=None, callback=None): | |||
def add_event(self, rule, callback=None): |
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.
Is there a reason callback
is allowed to be None here? I would think failing to pass a callback is almost always a bug.
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'm guessing it was convenient for tests. Maybe @llllllllll knows more.
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.
Yeah, I don't think there are good defaults for either. We should make them required.
@@ -546,11 +557,14 @@ class StatefulRule(EventRule): | |||
def __init__(self, rule=None): | |||
self.rule = rule or Always() | |||
|
|||
def new_should_trigger(self, callable_): |
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.
Why was this 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.
I didn't find any call sites.
zipline/utils/events.py
Outdated
@@ -236,6 +236,8 @@ def handle_data(self, context, data, dt): | |||
|
|||
|
|||
class EventRule(six.with_metaclass(ABCMeta)): | |||
cal = None # A calendar instance is set when scheduling a function. |
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.
Maybe worth clarifying that the calendar is set on instances of the rule, as opposed to the class?
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.
Should we make cal
an abstract property to ensure that all the subclasses implement setters?
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 thought about that as well. My only concern was about the performance of the properties inside the should_trigger
implementation, but I didn't validate that, and @lazyval
could also solve that.
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 think for simple attribute access property
will actually be faster than lazyval
. lazyval has more complicated machinery in exchange for memoizing the result, but if the fetching the attribute is trivial, then I think property will probably have less overhead.
Agreed. I went through the same thought process, and settled on this PR. |
a44a2a4
to
704e0cd
Compare
704e0cd
to
93fa848
Compare
Otherwise algos crash with
if a function is scheduled with, e.g.