diff --git a/zipline/pipeline/factors/technical.py b/zipline/pipeline/factors/technical.py index 3eb7eda2..f67471fc 100644 --- a/zipline/pipeline/factors/technical.py +++ b/zipline/pipeline/factors/technical.py @@ -23,7 +23,7 @@ from numexpr import evaluate from zipline.pipeline.data import USEquityPricing from zipline.pipeline.mixins import SingleInputMixin -from zipline.utils.control_flow import ignore_nanwarnings +from zipline.utils.numpy_utils import ignore_nanwarnings from zipline.utils.input_validation import expect_types from zipline.utils.math_utils import ( nanargmax, diff --git a/zipline/utils/control_flow.py b/zipline/utils/control_flow.py index 24fe3fcb..253a71b3 100644 --- a/zipline/utils/control_flow.py +++ b/zipline/utils/control_flow.py @@ -2,10 +2,6 @@ Control flow utilities. """ from six import iteritems -from warnings import ( - catch_warnings, - filterwarnings, -) class nullctx(object): @@ -23,40 +19,6 @@ class nullctx(object): return False -class WarningContext(object): - """ - Re-entrant contextmanager for contextually managing warnings. - """ - def __init__(self, *warning_specs): - self._warning_specs = warning_specs - self._catchers = [] - - def __enter__(self): - catcher = catch_warnings() - catcher.__enter__() - self._catchers.append(catcher) - for args, kwargs in self._warning_specs: - filterwarnings(*args, **kwargs) - return catcher - - def __exit__(self, *exc_info): - catcher = self._catchers.pop() - return catcher.__exit__(*exc_info) - - -def ignore_nanwarnings(): - """ - Helper for building a WarningContext that ignores warnings from numpy's - nanfunctions. - """ - return WarningContext( - ( - ('ignore',), - {'category': RuntimeWarning, 'module': 'numpy.lib.nanfunctions'}, - ) - ) - - def invert(d): """ Invert a dictionary into a dictionary of sets. diff --git a/zipline/utils/numpy_utils.py b/zipline/utils/numpy_utils.py index 79bca175..a873d7c0 100644 --- a/zipline/utils/numpy_utils.py +++ b/zipline/utils/numpy_utils.py @@ -2,6 +2,11 @@ Utilities for working with numpy arrays. """ from datetime import datetime +from warnings import ( + catch_warnings, + filterwarnings, +) + from numpy import ( broadcast, busday_count, @@ -219,3 +224,37 @@ def busday_count_mask_NaT(begindates, # Fill in entries where either comparison was NaT with nan in the output. out[beginmask | endmask] = nan return out + + +class WarningContext(object): + """ + Re-usable contextmanager for contextually managing warnings. + """ + def __init__(self, *warning_specs): + self._warning_specs = warning_specs + self._catchers = [] + + def __enter__(self): + catcher = catch_warnings() + catcher.__enter__() + self._catchers.append(catcher) + for args, kwargs in self._warning_specs: + filterwarnings(*args, **kwargs) + return self + + def __exit__(self, *exc_info): + catcher = self._catchers.pop() + return catcher.__exit__(*exc_info) + + +def ignore_nanwarnings(): + """ + Helper for building a WarningContext that ignores warnings from numpy's + nanfunctions. + """ + return WarningContext( + ( + ('ignore',), + {'category': RuntimeWarning, 'module': 'numpy.lib.nanfunctions'}, + ) + )