diff --git a/etc/requirements_dev.txt b/etc/requirements_dev.txt index 9bdd4425..dff67111 100644 --- a/etc/requirements_dev.txt +++ b/etc/requirements_dev.txt @@ -26,12 +26,10 @@ testfixtures==4.1.2 # Linting -flake8==2.4.1 -mccabe==0.3.1 -# Note: Old version of pep8 required by flake8 2.4.1 -pep8==1.5.7 -# Note: Old version of pyflakes required by flake8 2.4.1 -pyflakes==0.8.1 +flake8==3.3.0 +mccabe==0.6.0 +pycodestyle==2.3.1 +pyflakes==1.5.0 # Documentation Conversion diff --git a/tests/calendars/test_trading_calendar.py b/tests/calendars/test_trading_calendar.py index 0ede45c3..f463ff2d 100644 --- a/tests/calendars/test_trading_calendar.py +++ b/tests/calendars/test_trading_calendar.py @@ -35,10 +35,10 @@ from zipline.errors import ( ) from zipline.testing.predicates import assert_equal -from zipline.utils.calendars import( - register_calendar, +from zipline.utils.calendars import ( deregister_calendar, get_calendar, + register_calendar, ) from zipline.utils.calendars.calendar_utils import ( _default_calendar_aliases, diff --git a/tests/pipeline/test_term.py b/tests/pipeline/test_term.py index 39d507ca..7de90103 100644 --- a/tests/pipeline/test_term.py +++ b/tests/pipeline/test_term.py @@ -71,6 +71,7 @@ class SomeFactor(Factor): window_length = 5 inputs = [SomeDataSet.foo, SomeDataSet.bar] + SomeFactorAlias = SomeFactor diff --git a/tests/resources/pipeline_inputs/generate.py b/tests/resources/pipeline_inputs/generate.py index 42021d40..b3fe3080 100644 --- a/tests/resources/pipeline_inputs/generate.py +++ b/tests/resources/pipeline_inputs/generate.py @@ -37,5 +37,6 @@ def main(): print("Writing %s -> %s" % (symbol, dest)) data.to_csv(dest, index_label='day') + if __name__ == '__main__': main() diff --git a/tests/test_execution_styles.py b/tests/test_execution_styles.py index 05d81698..7d606463 100644 --- a/tests/test_execution_styles.py +++ b/tests/test_execution_styles.py @@ -15,9 +15,7 @@ from nose_parameterized import parameterized from six.moves import range -from zipline.errors import( - BadOrderParameters -) +from zipline.errors import BadOrderParameters from zipline.finance.execution import ( LimitOrder, MarketOrder, diff --git a/tests/test_restrictions.py b/tests/test_restrictions.py index 9b7a65d2..72c1297d 100644 --- a/tests/test_restrictions.py +++ b/tests/test_restrictions.py @@ -25,6 +25,7 @@ from zipline.testing.fixtures import ( def str_to_ts(dt_str): return pd.Timestamp(dt_str, tz='UTC') + FROZEN = RESTRICTION_STATES.FROZEN ALLOWED = RESTRICTION_STATES.ALLOWED MINUTE = pd.Timedelta(minutes=1) diff --git a/zipline/__init__.py b/zipline/__init__.py index 765e28d7..34eac834 100644 --- a/zipline/__init__.py +++ b/zipline/__init__.py @@ -15,6 +15,44 @@ import os +# This is *not* a place to dump arbitrary classes/modules for convenience, +# it is a place to expose the public interfaces. +from . import data +from . import finance +from . import gens +from . import utils +from .utils.calendars import get_calendar +from .utils.run_algo import run_algorithm +from ._version import get_versions + +# These need to happen after the other imports. +from . algorithm import TradingAlgorithm +from . import api + + +# PERF: Fire a warning if calendars were instantiated during zipline import. +# Having calendars doesn't break anything per-se, but it makes zipline imports +# noticeably slower, which becomes particularly noticeable in the Zipline CLI. +from zipline.utils.calendars.calendar_utils import global_calendar_dispatcher +if global_calendar_dispatcher._calendars: + import warnings + warnings.warn( + "Found TradingCalendar instances after zipline import.\n" + "Zipline startup will be much slower until this is fixed!", + ) + del warnings +del global_calendar_dispatcher + + +__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') + + if os.name == 'nt': # we need to be able to write to our temp directoy on windows so we # create a subdir in %TMP% that has write access and use that as %TMP% @@ -32,44 +70,6 @@ if os.name == 'nt': del _ -# This is *not* a place to dump arbitrary classes/modules for convenience, -# it is a place to expose the public interfaces. -from . import data -from . import finance -from . import gens -from . import utils -from .utils.calendars import get_calendar -from .utils.run_algo import run_algorithm -from ._version import 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') - - -# PERF: Fire a warning if calendars were instantiated during zipline import. -# Having calendars doesn't break anything per-se, but it makes zipline imports -# noticeably slower, which becomes particularly noticeable in the Zipline CLI. -from zipline.utils.calendars.calendar_utils import global_calendar_dispatcher -if global_calendar_dispatcher._calendars: - import warnings - warnings.warn( - "Found TradingCalendar instances after zipline import.\n" - "Zipline startup will be much slower until this is fixed!", - ) - del warnings -del global_calendar_dispatcher - - __all__ = [ 'TradingAlgorithm', 'api', diff --git a/zipline/assets/assets.py b/zipline/assets/assets.py index e27fa928..1e73bdae 100644 --- a/zipline/assets/assets.py +++ b/zipline/assets/assets.py @@ -1365,6 +1365,7 @@ class PricingDataAssociable(with_metaclass(ABCMeta)): """ pass + PricingDataAssociable.register(Asset) PricingDataAssociable.register(Future) PricingDataAssociable.register(ContinuousFuture) diff --git a/zipline/data/bundles/core.py b/zipline/data/bundles/core.py index 82e92ad4..50da9435 100644 --- a/zipline/data/bundles/core.py +++ b/zipline/data/bundles/core.py @@ -618,4 +618,5 @@ def _make_bundle_core(): return BundleCore(bundles, register, unregister, ingest, load, clean) + bundles, register, unregister, ingest, load, clean = _make_bundle_core() diff --git a/zipline/pipeline/factors/technical.py b/zipline/pipeline/factors/technical.py index 0700677d..3fa7756c 100644 --- a/zipline/pipeline/factors/technical.py +++ b/zipline/pipeline/factors/technical.py @@ -805,6 +805,7 @@ class AnnualizedVolatility(CustomFactor): def compute(self, today, assets, out, returns, annualization_factor): out[:] = nanstd(returns, axis=0) * (annualization_factor ** .5) + # Convenience aliases. EWMA = ExponentialWeightedMovingAverage EWMSTD = ExponentialWeightedMovingStdDev diff --git a/zipline/sources/requests_csv.py b/zipline/sources/requests_csv.py index 57d683f4..633ad253 100644 --- a/zipline/sources/requests_csv.py +++ b/zipline/sources/requests_csv.py @@ -55,6 +55,7 @@ class FetcherCSVRedirectError(ZiplineError): super(FetcherCSVRedirectError, self).__init__(*args, **kwargs) + # The following optional arguments are supported for # requests backed data sources. # see http://docs.python-requests.org/en/latest/api/#main-interface @@ -63,7 +64,8 @@ ALLOWED_REQUESTS_KWARGS = { 'params', 'headers', 'auth', - 'cert'} + 'cert' +} # The following optional arguments are supported for pandas' read_csv diff --git a/zipline/test_algorithms.py b/zipline/test_algorithms.py index 22acb5dd..de6e923a 100644 --- a/zipline/test_algorithms.py +++ b/zipline/test_algorithms.py @@ -789,6 +789,7 @@ def handle_data_api(context, data): record(incr=context.incr) + ########################### # AlgoScripts as strings noop_algo = """ diff --git a/zipline/testing/core.py b/zipline/testing/core.py index 34be29a5..6afe1e4e 100644 --- a/zipline/testing/core.py +++ b/zipline/testing/core.py @@ -1142,7 +1142,8 @@ def parameter_space(__fail_fast=False, **params): "supplied to parameter_space()." % extra ) - make_param_sets = lambda: product(*(params[name] for name in argnames)) + def make_param_sets(): + return product(*(params[name] for name in argnames)) if __fail_fast: @wraps(f) diff --git a/zipline/utils/functional.py b/zipline/utils/functional.py index 716e8777..f8eb45e8 100644 --- a/zipline/utils/functional.py +++ b/zipline/utils/functional.py @@ -5,6 +5,8 @@ from six import viewkeys from six.moves import map, zip from toolz import curry, flip +from .sentinel import sentinel + @curry def apply(f, *args, **kwargs): @@ -57,8 +59,6 @@ def apply(f, *args, **kwargs): # Alias for use as a class decorator. instance = apply -from zipline.utils.sentinel import sentinel - def mapall(funcs, seq): """ diff --git a/zipline/utils/sentinel.py b/zipline/utils/sentinel.py index 8015acaf..ad761e85 100644 --- a/zipline/utils/sentinel.py +++ b/zipline/utils/sentinel.py @@ -57,4 +57,6 @@ def sentinel(name, doc=None): sentinel._cache[name] = Sentinel # cache result return Sentinel + + sentinel._cache = {} diff --git a/zipline/utils/tradingcalendar.py b/zipline/utils/tradingcalendar.py index 778c6019..6f5698d4 100644 --- a/zipline/utils/tradingcalendar.py +++ b/zipline/utils/tradingcalendar.py @@ -266,6 +266,7 @@ def get_non_trading_days(start, end): non_trading_days.sort() return pd.DatetimeIndex(non_trading_days) + non_trading_days = get_non_trading_days(start, end) trading_day = pd.tseries.offsets.CDay(holidays=non_trading_days) @@ -275,6 +276,7 @@ def get_trading_days(start, end, trading_day=trading_day): end=end.date(), freq=trading_day).tz_localize('UTC') + trading_days = get_trading_days(start, end) @@ -384,6 +386,7 @@ def get_early_closes(start, end): early_closes.sort() return pd.DatetimeIndex(early_closes) + early_closes = get_early_closes(start, end) @@ -420,5 +423,6 @@ def get_open_and_closes(trading_days, early_closes, get_open_and_close): return open_and_closes + open_and_closes = get_open_and_closes(trading_days, early_closes, get_open_and_close)