Skip to content

Commit d831178

Browse files
added functionality to suppress data instantiation warnings
1 parent 1120635 commit d831178

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

strategy/strategy.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
import pandas_market_calendars as mcal
1414
from abc import ABCMeta, abstractmethod
1515

16+
# control data warnings in object instantation, see
17+
# https://docs.python.org/3/library/warnings.html#the-warnings-filter
18+
WARNINGS = "default"
19+
1620

1721
class Exposures():
1822
"""
@@ -116,7 +120,9 @@ def security_mapping(x):
116120
warning = (warning + "Expiry data without futures"
117121
" price data:{0}\n".format(extra_expiries))
118122
if warning:
119-
warnings.warn(warning)
123+
with warnings.catch_warnings():
124+
warnings.simplefilter(WARNINGS)
125+
warnings.warn(warning)
120126

121127
@classmethod
122128
def _validate_expiries(cls, expiries):
@@ -556,7 +562,9 @@ def __init__(self, exposures, start_date, end_date,
556562
"missing price data for tradeable calendar dates:\n"
557563
"{2}\n".format(ast, exch, missing_dts))
558564
if warning:
559-
warnings.warn(warning)
565+
with warnings.catch_warnings():
566+
warnings.simplefilter(WARNINGS)
567+
warnings.warn(warning)
560568

561569
if holidays:
562570
calendar = _AdhocExchangeCalendar(holidays)

tests/test_strategy.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
from strategy.portfolios import ExpiryPortfolio
22
from strategy.strategy import Exposures
3+
import strategy.strategy as strat
34
import pandas as pd
45
import unittest
56
from collections import namedtuple
67
import os
78
from pandas.util.testing import assert_frame_equal, assert_series_equal, \
89
assert_index_equal
910

11+
# suppress missing price data warnings
12+
strat.WARNINGS = "ignore"
13+
1014

1115
class TestExpiryPortfolio(unittest.TestCase):
1216

0 commit comments

Comments
 (0)