mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-28 07:48:45 +08:00
MAINT: Move ignore_nanwarnings to numpy_utils.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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'},
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user