mirror of
https://github.com/wassname/catalyst.git
synced 2026-09-12 12:12:04 +08:00
MAINT: PR cleanup
This commit is contained in:
+17
-14
@@ -12,6 +12,7 @@
|
||||
# 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.
|
||||
import warnings
|
||||
from collections import namedtuple
|
||||
import datetime
|
||||
from datetime import timedelta
|
||||
@@ -34,7 +35,6 @@ import pytz
|
||||
from pandas.io.common import PerformanceWarning
|
||||
|
||||
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
|
||||
@@ -1959,7 +1959,9 @@ def handle_data(context, data):
|
||||
pass
|
||||
""")
|
||||
|
||||
with WarningsCatcher([PerformanceWarning]) as w:
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("ignore", PerformanceWarning)
|
||||
|
||||
algo = TradingAlgorithm(
|
||||
script=algocode,
|
||||
sim_params=sim_params,
|
||||
@@ -1967,18 +1969,19 @@ def handle_data(context, data):
|
||||
)
|
||||
algo.run(self.data_portal)
|
||||
|
||||
self.assertEqual(len(w), 2)
|
||||
for i, warning in enumerate(w):
|
||||
self.assertIsInstance(warning.message, UserWarning)
|
||||
self.assertEqual(
|
||||
warning.message.args[0],
|
||||
'Got a time rule for the second positional argument '
|
||||
'date_rule. You should use keyword argument '
|
||||
'time_rule= when calling schedule_function without '
|
||||
'specifying a date_rule'
|
||||
)
|
||||
# The warnings come from line 13 and 14 in the algocode
|
||||
self.assertEqual(warning.lineno, 13 + i)
|
||||
self.assertEqual(len(w), 2)
|
||||
|
||||
for i, warning in enumerate(w):
|
||||
self.assertIsInstance(warning.message, UserWarning)
|
||||
self.assertEqual(
|
||||
warning.message.args[0],
|
||||
'Got a time rule for the second positional argument '
|
||||
'date_rule. You should use keyword argument '
|
||||
'time_rule= when calling schedule_function without '
|
||||
'specifying a date_rule'
|
||||
)
|
||||
# The warnings come from line 13 and 14 in the algocode
|
||||
self.assertEqual(warning.lineno, 13 + i)
|
||||
|
||||
self.assertEqual(
|
||||
algo.done_at_open,
|
||||
|
||||
+12
-7
@@ -5,7 +5,6 @@ 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
|
||||
@@ -292,7 +291,8 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
cease to be supported, we also want to assert that we're seeing a
|
||||
deprecation warning.
|
||||
"""
|
||||
with WarningsCatcher([PerformanceWarning]) as w:
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("ignore", PerformanceWarning)
|
||||
warnings.simplefilter("default", ZiplineDeprecationWarning)
|
||||
algo = self.create_algo(sid_accessor_algo)
|
||||
algo.run(self.data_portal)
|
||||
@@ -320,7 +320,8 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
We also want to assert that we warn that iterating over the assets
|
||||
in `data` is deprecated.
|
||||
"""
|
||||
with WarningsCatcher([PerformanceWarning]) as w:
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("ignore", PerformanceWarning)
|
||||
warnings.simplefilter("default", ZiplineDeprecationWarning)
|
||||
algo = self.create_algo(data_items_algo)
|
||||
algo.run(self.data_portal)
|
||||
@@ -344,7 +345,8 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
)
|
||||
|
||||
def test_iterate_data(self):
|
||||
with WarningsCatcher([PerformanceWarning]) as w:
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("ignore", PerformanceWarning)
|
||||
warnings.simplefilter("default", ZiplineDeprecationWarning)
|
||||
|
||||
algo = self.create_algo(simple_algo)
|
||||
@@ -374,7 +376,8 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
)
|
||||
|
||||
def test_history(self):
|
||||
with WarningsCatcher([PerformanceWarning]) as w:
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("ignore", PerformanceWarning)
|
||||
warnings.simplefilter("default", ZiplineDeprecationWarning)
|
||||
|
||||
sim_params = self.sim_params.create_new(
|
||||
@@ -415,7 +418,8 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
expected_vol_with_split)
|
||||
|
||||
def test_simple_transforms(self):
|
||||
with WarningsCatcher([PerformanceWarning]) as w:
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("ignore", PerformanceWarning)
|
||||
warnings.simplefilter("default", ZiplineDeprecationWarning)
|
||||
|
||||
sim_params = SimulationParameters(
|
||||
@@ -485,7 +489,8 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
self.assertAlmostEqual(346, algo.returns)
|
||||
|
||||
def test_manipulation(self):
|
||||
with WarningsCatcher([PerformanceWarning]) as w:
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("ignore", PerformanceWarning)
|
||||
warnings.simplefilter("default", ZiplineDeprecationWarning)
|
||||
|
||||
algo = self.create_algo(simple_algo)
|
||||
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
from datetime import time
|
||||
from unittest import TestCase
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from zipline.gens.sim_engine import (
|
||||
MinuteSimulationClock,
|
||||
SESSION_START,
|
||||
@@ -26,8 +25,8 @@ class TestClock(TestCase):
|
||||
)
|
||||
|
||||
trading_o_and_c = cls.nyse_calendar.schedule.ix[cls.sessions]
|
||||
cls.opens = trading_o_and_c['market_open'].values.astype(np.int64)
|
||||
cls.closes = trading_o_and_c['market_close'].values.astype(np.int64)
|
||||
cls.opens = trading_o_and_c['market_open']
|
||||
cls.closes = trading_o_and_c['market_close']
|
||||
|
||||
def test_bts_before_session(self):
|
||||
clock = MinuteSimulationClock(
|
||||
|
||||
@@ -120,6 +120,7 @@ class MinuteToDailyAggregationTestCase(WithBcolzEquityMinuteBarReader,
|
||||
self.equity_daily_aggregator = DailyHistoryAggregator(
|
||||
self.trading_calendar.schedule.market_open,
|
||||
self.bcolz_equity_minute_bar_reader,
|
||||
self.trading_calendar
|
||||
)
|
||||
|
||||
@parameterized.expand([
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
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
|
||||
Reference in New Issue
Block a user