mirror of
https://github.com/saymrwulf/zipline.git
synced 2026-05-14 20:58:10 +00:00
TST: Set numpy array formatting to legacy for doctest
TST: Ignore runtime warnings for invalid division only in newer pandas
This commit is contained in:
parent
61e472477b
commit
ddec0714c9
3 changed files with 49 additions and 1 deletions
|
|
@ -0,0 +1 @@
|
|||
from zipline import setup, teardown # noqa For nosetests
|
||||
|
|
@ -12,15 +12,20 @@
|
|||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from distutils.version import StrictVersion
|
||||
import os
|
||||
from trading_calendars import get_calendar
|
||||
import numpy as np
|
||||
|
||||
# This is *not* a place to dump arbitrary classes/modules for convenience,
|
||||
# it is a place to expose the public interfaces.
|
||||
from trading_calendars import get_calendar
|
||||
|
||||
from . import data
|
||||
from . import finance
|
||||
from . import gens
|
||||
from . import utils
|
||||
from .utils.numpy_utils import numpy_version
|
||||
from .utils.pandas_utils import new_pandas
|
||||
from .utils.run_algo import run_algorithm
|
||||
from ._version import get_versions
|
||||
|
||||
|
|
@ -79,3 +84,42 @@ __all__ = [
|
|||
'run_algorithm',
|
||||
'utils',
|
||||
]
|
||||
|
||||
|
||||
def setup(self,
|
||||
np=np,
|
||||
numpy_version=numpy_version,
|
||||
StrictVersion=StrictVersion,
|
||||
new_pandas=new_pandas):
|
||||
"""Lives in zipline.__init__ for doctests."""
|
||||
|
||||
legacy_version = '1.13'
|
||||
if numpy_version > StrictVersion(legacy_version):
|
||||
self.old_opts = np.get_printoptions()
|
||||
np.set_printoptions(legacy=legacy_version)
|
||||
else:
|
||||
self.old_opts = None
|
||||
|
||||
if new_pandas:
|
||||
self.old_err = np.geterr()
|
||||
# old pandas has numpy compat that sets this
|
||||
np.seterr(all='ignore')
|
||||
else:
|
||||
self.old_err = None
|
||||
|
||||
|
||||
def teardown(self, np=np):
|
||||
"""Lives in zipline.__init__ for doctests."""
|
||||
|
||||
if self.old_err is not None:
|
||||
np.seterr(**self.old_err)
|
||||
|
||||
if self.old_opts is not None:
|
||||
np.set_printoptions(**self.old_opts)
|
||||
|
||||
|
||||
del os
|
||||
del np
|
||||
del numpy_version
|
||||
del StrictVersion
|
||||
del new_pandas
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ Utilities for working with numpy arrays.
|
|||
"""
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
from distutils.version import StrictVersion
|
||||
from warnings import (
|
||||
catch_warnings,
|
||||
filterwarnings,
|
||||
|
|
@ -26,6 +27,8 @@ from numpy import (
|
|||
from numpy.lib.stride_tricks import as_strided
|
||||
from toolz import flip
|
||||
|
||||
numpy_version = StrictVersion(np.__version__)
|
||||
|
||||
uint8_dtype = dtype('uint8')
|
||||
bool_dtype = dtype('bool')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue