MAINT: Updates from Joe's PR feedback.

This commit is contained in:
Scott Sanderson
2016-09-07 20:42:19 -04:00
parent 977d1fa0b9
commit d6ad73e064
7 changed files with 26 additions and 17 deletions
+4 -4
View File
@@ -37,12 +37,12 @@ class CalendarAliasTestCase(ZiplineTestCase):
def test_follow_alias_chain(self):
self.assertIs(
self.dispatcher.get_calendar('ICE'),
self.dispatcher.get_calendar('ICE_ALIAS'),
self.dispatcher.get_calendar('ICE'),
)
self.assertIs(
self.dispatcher.get_calendar('ICE'),
self.dispatcher.get_calendar('ICE_ALIAS_ALIAS'),
self.dispatcher.get_calendar('ICE'),
)
def test_add_new_aliases(self):
@@ -52,8 +52,8 @@ class CalendarAliasTestCase(ZiplineTestCase):
self.dispatcher.register_calendar_alias('NOT_ICE', 'ICE')
self.assertIs(
self.dispatcher.get_calendar('ICE'),
self.dispatcher.get_calendar('NOT_ICE'),
self.dispatcher.get_calendar('ICE'),
)
self.dispatcher.register_calendar_alias(
@@ -61,8 +61,8 @@ class CalendarAliasTestCase(ZiplineTestCase):
'ICE_ALIAS_ALIAS'
)
self.assertIs(
self.dispatcher.get_calendar('ICE'),
self.dispatcher.get_calendar('ICE_ALIAS_ALIAS_ALIAS'),
self.dispatcher.get_calendar('ICE'),
)
def test_remove_aliases(self):
+1 -1
View File
@@ -369,7 +369,7 @@ class BundleCoreTestCase(WithInstanceTmpDir,
"""
if not self.bundles:
@self.register('bundle',
calendar_name=('NYSE'),
calendar_name='NYSE',
start_session=pd.Timestamp('2014', tz='UTC'),
end_session=pd.Timestamp('2014', tz='UTC'))
def _(environ,
+4 -2
View File
@@ -41,14 +41,16 @@ from . import utils
from .utils.calendars import get_calendar
from .utils.run_algo import run_algorithm
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
# These need to happen after the other imports.
from . algorithm import TradingAlgorithm
from . import api
__version__ = get_versions()['version']
del get_versions
def load_ipython_extension(ipython):
from .__main__ import zipline_magic
ipython.register_magic_function(zipline_magic, 'line_cell', 'zipline')
-3
View File
@@ -619,6 +619,3 @@ def _make_bundle_core():
return BundleCore(bundles, register, unregister, ingest, load, clean)
bundles, register, unregister, ingest, load, clean = _make_bundle_core()
register_calendar_alias("YAHOO", "NYSE")
register_calendar_alias("QUANDL", "NYSE")
+6 -1
View File
@@ -12,9 +12,11 @@ import pandas as pd
import requests
from six.moves.urllib.parse import urlencode
from . import core as bundles
from zipline.utils.calendars import register_calendar_alias
from zipline.utils.cli import maybe_show_progress
from . import core as bundles
log = Logger(__name__)
seconds_per_call = (pd.Timedelta('10 minutes') / 2000).total_seconds()
# Invalid symbols that quandl has had in its metadata:
@@ -402,3 +404,6 @@ def quantopian_quandl_bundle(environ,
if show_progress:
print("Writing data to %s." % output_dir)
tar.extractall(output_dir)
register_calendar_alias("QUANDL", "NYSE")
+3
View File
@@ -5,6 +5,7 @@ import pandas as pd
from pandas_datareader.data import DataReader
import requests
from zipline.utils.calendars import register_calendar_alias
from zipline.utils.cli import maybe_show_progress
from .core import register
@@ -198,3 +199,5 @@ register(
pd.Timestamp('2015-01-01', tz='utc'),
),
)
register_calendar_alias("YAHOO", "NYSE")
+8 -6
View File
@@ -48,8 +48,9 @@ class TradingCalendarDispatcher(object):
calendars : dict[str -> TradingCalendar]
Initial set of calendars.
calendar_factories : dict[str -> function]
Factories for lazy
Factories for lazy calendar creation.
aliases : dict[str -> str]
Calendar name aliases.
"""
def __init__(self, calendars, calendar_factories, aliases):
self._calendars = calendars
@@ -211,17 +212,18 @@ class TradingCalendarDispatcher(object):
"""
# Use an OrderedDict as an ordered set so that we can return the order
# of aliases in the event of a cycle.
seen = OrderedDict({name: None})
seen = []
while name in self._aliases:
seen[name] = None
seen.append(name)
name = self._aliases[name]
# This is O(N ** 2), but if there's an alias chain longer than 2,
# something strange has happened.
if name in seen:
cycle = seen.keys()
cycle.append(name)
seen.append(name)
raise CyclicCalendarAlias(
cycle=" -> ".join([repr(k) for k in cycle])
cycle=" -> ".join(repr(k) for k in seen)
)
return name