mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-01 09:59:46 +08:00
DEV: Don't log an error if we can't find a matching asset/field/day triple in fetcher data
This commit is contained in:
@@ -595,3 +595,36 @@ def before_trading_start(context, data):
|
||||
np.testing.assert_array_almost_equal(values[55:64], [2.50233] * 9)
|
||||
np.testing.assert_array_almost_equal(values[64:75], [2.550829] * 11)
|
||||
np.testing.assert_array_almost_equal(values[75:], [2.64484] * 35)
|
||||
|
||||
def test_fetcher_bad_data(self):
|
||||
self.responses.add(
|
||||
self.responses.GET,
|
||||
'https://fake.urls.com/fetcher_nflx_data.csv',
|
||||
body=NFLX_DATA,
|
||||
content_type='text/csv',
|
||||
)
|
||||
|
||||
sim_params = factory.create_simulation_parameters(
|
||||
start=pd.Timestamp("2013-06-12", tz='UTC'),
|
||||
end=pd.Timestamp("2013-06-14", tz='UTC'),
|
||||
data_frequency="minute"
|
||||
)
|
||||
|
||||
results = self.run_algo("""
|
||||
from zipline.api import fetch_csv, symbol
|
||||
import numpy as np
|
||||
|
||||
def initialize(context):
|
||||
fetch_csv('https://fake.urls.com/fetcher_nflx_data.csv',
|
||||
date_column = 'Settlement Date',
|
||||
date_format = '%m/%d/%y')
|
||||
context.nflx = symbol('NFLX')
|
||||
context.aapl = symbol('AAPL')
|
||||
|
||||
def handle_data(context, data):
|
||||
assert np.isnan(data.current(context.nflx, 'invalid_column'))
|
||||
assert np.isnan(data.current(context.aapl, 'invalid_column'))
|
||||
assert np.isnan(data.current(context.aapl, 'dtc'))
|
||||
""", sim_params=sim_params, data_frequency="minute")
|
||||
|
||||
self.assertEqual(3, len(results))
|
||||
|
||||
@@ -646,8 +646,8 @@ class DataPortal(object):
|
||||
# If we have an extra source with a column called "price", only look
|
||||
# at it if it's on something like palladium and not AAPL (since our
|
||||
# own price data always wins when dealing with assets).
|
||||
return field in map and not (field in BASE_FIELDS and
|
||||
isinstance(asset, Asset))
|
||||
|
||||
return not (field in BASE_FIELDS and isinstance(asset, Asset))
|
||||
|
||||
def get_spot_value(self, asset, field, dt, data_frequency):
|
||||
"""
|
||||
@@ -680,14 +680,7 @@ class DataPortal(object):
|
||||
try:
|
||||
return \
|
||||
self._augmented_sources_map[field][asset].loc[day, field]
|
||||
except:
|
||||
log.error(
|
||||
"Could not find value for asset={0}, day={1},"
|
||||
"column={2}".format(
|
||||
str(asset),
|
||||
str(day),
|
||||
str(field)))
|
||||
|
||||
except KeyError:
|
||||
return np.NaN
|
||||
|
||||
if field not in BASE_FIELDS:
|
||||
|
||||
Reference in New Issue
Block a user