-
Notifications
You must be signed in to change notification settings - Fork 382
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
ENH: Pass kwargs to calendar init #176
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,15 +162,18 @@ def __init__(self, calendars, calendar_factories, aliases): | |
self._calendar_factories = dict(calendar_factories) | ||
self._aliases = dict(aliases) | ||
|
||
def get_calendar(self, name): | ||
def get_calendar(self, name, **kwargs): | ||
""" | ||
Retrieves an instance of an TradingCalendar whose name is given. | ||
|
||
Parameters | ||
---------- | ||
name : str | ||
The name of the TradingCalendar to be retrieved. | ||
|
||
kwargs: Dict[str, Any] | ||
Optional keyword args passed to calendar `__init__. | ||
Note: Arguments are only passed when the calendar is first | ||
constructed. Subsequent calls will not affect the calendar. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This confusion is my biggest concern. What do you think about a warning for subsequent calls with kwargs? Or warn if they don't match the original? Or create a new calendar if it doesn't match? Maybe it would be clearer for people to use the more obvious mutator Having Looking at that original zipline issue, where should someone call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see the argument for moving I can definitely add a warning here if you don't think that would be too noisy.
I think zipline should either pass the dates it wants here (i.e. passing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the expectation is that that particular call site will actually construct the calendar, that feels brittle to me, since it's not enforced. Every third-party extension or zipline module will have to be sure not to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Then should we have zipline not use the registry? I can add some sort of In general, I feel that we should lean towards making the standalone usage of
If you use the cli main entry point, that's the first instance we grab the calendar. |
||
Returns | ||
------- | ||
calendar : calendars.TradingCalendar | ||
|
@@ -191,7 +194,7 @@ def get_calendar(self, name): | |
raise InvalidCalendarName(calendar_name=name) | ||
|
||
# Cache the calendar for future use. | ||
calendar = self._calendars[canonical_name] = factory() | ||
calendar = self._calendars[canonical_name] = factory(**kwargs) | ||
return calendar | ||
|
||
def get_calendar_names(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.
Looks like this isn't true anymore. Do we no longer have that speed concern and/or shall we update this comment?
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.
Yep - I should update this comment.