mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-23 12:50:22 +08:00
TST: Filter out pandas performance warnings in tests (for now)
This commit is contained in:
@@ -16,7 +16,6 @@ from collections import namedtuple
|
||||
import datetime
|
||||
from datetime import timedelta
|
||||
from textwrap import dedent
|
||||
import warnings
|
||||
from unittest import skip
|
||||
from copy import deepcopy
|
||||
|
||||
@@ -32,11 +31,11 @@ from testfixtures import TempDirectory
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import pytz
|
||||
from pandas.io.common import PerformanceWarning
|
||||
|
||||
from zipline import (
|
||||
run_algorithm,
|
||||
TradingAlgorithm,
|
||||
)
|
||||
from zipline import run_algorithm
|
||||
from tests.warnings_catcher import WarningsCatcher
|
||||
from zipline import TradingAlgorithm
|
||||
from zipline.api import FixedSlippage
|
||||
from zipline.assets import Equity, Future
|
||||
from zipline.assets.synthetic import (
|
||||
@@ -1960,7 +1959,7 @@ def handle_data(context, data):
|
||||
pass
|
||||
""")
|
||||
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
with WarningsCatcher([PerformanceWarning]) as w:
|
||||
algo = TradingAlgorithm(
|
||||
script=algocode,
|
||||
sim_params=sim_params,
|
||||
|
||||
@@ -3,7 +3,9 @@ import warnings
|
||||
from mock import patch
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from pandas.io.common import PerformanceWarning
|
||||
|
||||
from tests.warnings_catcher import WarningsCatcher
|
||||
from zipline import TradingAlgorithm
|
||||
from zipline.finance.trading import SimulationParameters
|
||||
from zipline.protocol import BarData
|
||||
@@ -290,7 +292,7 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
cease to be supported, we also want to assert that we're seeing a
|
||||
deprecation warning.
|
||||
"""
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
with WarningsCatcher([PerformanceWarning]) as w:
|
||||
warnings.simplefilter("default", ZiplineDeprecationWarning)
|
||||
algo = self.create_algo(sid_accessor_algo)
|
||||
algo.run(self.data_portal)
|
||||
@@ -318,7 +320,7 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
We also want to assert that we warn that iterating over the assets
|
||||
in `data` is deprecated.
|
||||
"""
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
with WarningsCatcher([PerformanceWarning]) as w:
|
||||
warnings.simplefilter("default", ZiplineDeprecationWarning)
|
||||
algo = self.create_algo(data_items_algo)
|
||||
algo.run(self.data_portal)
|
||||
@@ -342,7 +344,7 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
)
|
||||
|
||||
def test_iterate_data(self):
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
with WarningsCatcher([PerformanceWarning]) as w:
|
||||
warnings.simplefilter("default", ZiplineDeprecationWarning)
|
||||
|
||||
algo = self.create_algo(simple_algo)
|
||||
@@ -372,7 +374,7 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
)
|
||||
|
||||
def test_history(self):
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
with WarningsCatcher([PerformanceWarning]) as w:
|
||||
warnings.simplefilter("default", ZiplineDeprecationWarning)
|
||||
|
||||
sim_params = self.sim_params.create_new(
|
||||
@@ -413,7 +415,7 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
expected_vol_with_split)
|
||||
|
||||
def test_simple_transforms(self):
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
with WarningsCatcher([PerformanceWarning]) as w:
|
||||
warnings.simplefilter("default", ZiplineDeprecationWarning)
|
||||
|
||||
sim_params = SimulationParameters(
|
||||
@@ -483,7 +485,7 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
self.assertAlmostEqual(346, algo.returns)
|
||||
|
||||
def test_manipulation(self):
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
with WarningsCatcher([PerformanceWarning]) as w:
|
||||
warnings.simplefilter("default", ZiplineDeprecationWarning)
|
||||
|
||||
algo = self.create_algo(simple_algo)
|
||||
|
||||
+1
-3
@@ -7,7 +7,6 @@ from zipline.gens.sim_engine import (
|
||||
SESSION_START,
|
||||
BEFORE_TRADING_START_BAR,
|
||||
BAR,
|
||||
MINUTE_END,
|
||||
SESSION_END
|
||||
)
|
||||
|
||||
@@ -149,13 +148,12 @@ class TestClock(TestCase):
|
||||
bts_session_times[2]
|
||||
)
|
||||
|
||||
|
||||
def test_bts_after_session(self):
|
||||
clock = MinuteSimulationClock(
|
||||
self.sessions,
|
||||
self.opens,
|
||||
self.closes,
|
||||
days_at_time(self.sessions, time(19, 05), "US/Eastern"),
|
||||
days_at_time(self.sessions, time(19, 5), "US/Eastern"),
|
||||
False
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
from warnings import catch_warnings, WarningMessage
|
||||
|
||||
|
||||
class WarningsCatcher(catch_warnings):
|
||||
"""
|
||||
Subclass of warnings.catch_warnings that takes a list of warning types to
|
||||
ignore.
|
||||
"""
|
||||
def __init__(self, types_to_ignore=None):
|
||||
super(WarningsCatcher, self).__init__(record=True)
|
||||
|
||||
self._types_to_ignore = set(types_to_ignore or [])
|
||||
|
||||
def __enter__(self):
|
||||
if self._entered:
|
||||
raise RuntimeError("Cannot enter %r twice" % self)
|
||||
self._entered = True
|
||||
self._filters = self._module.filters
|
||||
self._module.filters = self._filters[:]
|
||||
self._showwarning = self._module.showwarning
|
||||
if self._record:
|
||||
log = []
|
||||
|
||||
def showwarning(*args, **kwargs):
|
||||
if args[1] in self._types_to_ignore:
|
||||
return
|
||||
log.append(WarningMessage(*args, **kwargs))
|
||||
|
||||
self._module.showwarning = showwarning
|
||||
return log
|
||||
else:
|
||||
return None
|
||||
@@ -766,6 +766,9 @@ def days_at_time(days, t, tz, day_offset=0):
|
||||
|
||||
# Shift all days to the target time in the local timezone, then
|
||||
# convert to UTC.
|
||||
|
||||
# FIXME: Once we're off Pandas 16, see if we can replace DateOffset with
|
||||
# TimeDelta.
|
||||
return days_offset.shift(
|
||||
1, freq=DateOffset(hour=t.hour, minute=t.minute, second=t.second)
|
||||
).tz_localize(tz).tz_convert('UTC')
|
||||
|
||||
Reference in New Issue
Block a user