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
Run chunked pipeline #1811
Merged
Merged
Run chunked pipeline #1811
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c03bed3
Add missing Python 3.5 references (now supported)
Peque 897de69
ENH: Add function to concatenate list of dataframes with categoricals
bdd1f15
ENH: Add function for running pipelines in chunks
a88df2b
ENH: Add run_chunked_pipeline method to PipelineEngine
69d1269
ENH: Include sharedoc function
6b19e45
ENH: Use context manager to suppress nan-categorical warning
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from pandas import Timestamp | ||
from nose_parameterized import parameterized | ||
|
||
from zipline.testing import ZiplineTestCase | ||
from zipline.utils.calendars import get_calendar | ||
from zipline.utils.date_utils import compute_date_range_chunks | ||
|
||
|
||
def T(s): | ||
""" | ||
Helpful function to improve readibility. | ||
""" | ||
return Timestamp(s, tz='UTC') | ||
|
||
|
||
class TestDateUtils(ZiplineTestCase): | ||
|
||
@classmethod | ||
def init_class_fixtures(cls): | ||
super(TestDateUtils, cls).init_class_fixtures() | ||
cls.calendar = get_calendar('NYSE') | ||
|
||
@parameterized.expand([ | ||
(None, [(T('2017-01-03'), T('2017-01-31'))]), | ||
(10, [ | ||
(T('2017-01-03'), T('2017-01-17')), | ||
(T('2017-01-18'), T('2017-01-31')) | ||
]), | ||
(15, [ | ||
(T('2017-01-03'), T('2017-01-24')), | ||
(T('2017-01-25'), T('2017-01-31')) | ||
]), | ||
]) | ||
def test_compute_date_range_chunks(self, chunksize, expected): | ||
# This date range results in 20 business days | ||
start_date = T('2017-01-03') | ||
end_date = T('2017-01-31') | ||
|
||
date_ranges = compute_date_range_chunks( | ||
self.calendar.all_sessions, | ||
start_date, | ||
end_date, | ||
chunksize | ||
) | ||
|
||
self.assertListEqual(list(date_ranges), expected) | ||
|
||
def test_compute_date_range_chunks_invalid_input(self): | ||
# Start date not found in calendar | ||
with self.assertRaises(KeyError) as cm: | ||
compute_date_range_chunks( | ||
self.calendar.all_sessions, | ||
T('2017-05-07'), # Sunday | ||
T('2017-06-01'), | ||
None | ||
) | ||
self.assertEqual( | ||
str(cm.exception), | ||
"'Start date 2017-05-07 is not found in calendar.'" | ||
) | ||
|
||
# End date not found in calendar | ||
with self.assertRaises(KeyError) as cm: | ||
compute_date_range_chunks( | ||
self.calendar.all_sessions, | ||
T('2017-05-01'), | ||
T('2017-05-27'), # Saturday | ||
None | ||
) | ||
self.assertEqual( | ||
str(cm.exception), | ||
"'End date 2017-05-27 is not found in calendar.'" | ||
) | ||
|
||
# End date before start date | ||
with self.assertRaises(ValueError) as cm: | ||
compute_date_range_chunks( | ||
self.calendar.all_sessions, | ||
T('2017-06-01'), | ||
T('2017-05-01'), | ||
None | ||
) | ||
self.assertEqual( | ||
str(cm.exception), | ||
"End date 2017-05-01 cannot precede start date 2017-06-01." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from zipline.testing import ZiplineTestCase | ||
from zipline.utils.sharedoc import copydoc | ||
|
||
|
||
class TestSharedoc(ZiplineTestCase): | ||
|
||
def test_copydoc(self): | ||
def original_docstring_function(): | ||
""" | ||
My docstring brings the boys to the yard. | ||
""" | ||
pass | ||
|
||
@copydoc(original_docstring_function) | ||
def copied_docstring_function(): | ||
pass | ||
|
||
self.assertEqual( | ||
original_docstring_function.__doc__, | ||
copied_docstring_function.__doc__ | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 include other columns of different dtypes to exercise the chunking categorical concat logic?