mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-07 11:20:19 +08:00
ENH: allows users to specify the cutoff time for data query in blaze
loaders This allows people to set their cutoff time to the time they will actually execute 'before_trading_start'. Currently this is just passed to the constructor of the loader; however, I would like to make this managed by the algorithm simulation runner. This would help keep all of the loaders in sync and lock 'before_trading_start's execution to the time the data is queried for.
This commit is contained in:
@@ -4,7 +4,7 @@ Tests for the blaze interface to the pipeline api.
|
||||
from __future__ import division
|
||||
|
||||
from collections import OrderedDict
|
||||
from datetime import timedelta
|
||||
from datetime import timedelta, time
|
||||
from unittest import TestCase
|
||||
import warnings
|
||||
|
||||
@@ -323,6 +323,43 @@ class BlazeToPipelineTestCase(TestCase):
|
||||
))
|
||||
assert_frame_equal(result, expected, check_dtype=False)
|
||||
|
||||
def test_custom_query_time_tz(self):
|
||||
df = self.df.copy()
|
||||
df['timestamp'] = (
|
||||
pd.DatetimeIndex(df['timestamp'], tz='EST') +
|
||||
timedelta(hours=8, minutes=45)
|
||||
).tz_convert('utc')
|
||||
df.ix[3:5, 'timestamp'] = pd.Timestamp('2014-01-01 13:46', tz='utc')
|
||||
expr = bz.Data(df, name='expr', dshape=self.dshape)
|
||||
loader = BlazeLoader(data_query_time=time(8, 45), data_query_tz='EST')
|
||||
ds = from_blaze(
|
||||
expr,
|
||||
loader=loader,
|
||||
no_deltas_rule=no_deltas_rules.ignore,
|
||||
)
|
||||
p = Pipeline()
|
||||
p.add(ds.value.latest, 'value')
|
||||
dates = self.dates
|
||||
|
||||
with tmp_asset_finder() as finder:
|
||||
result = SimplePipelineEngine(
|
||||
loader,
|
||||
dates,
|
||||
finder,
|
||||
).run_pipeline(p, dates[0], dates[-1])
|
||||
|
||||
expected = df.drop('asof_date', axis=1)
|
||||
expected['timestamp'] = expected['timestamp'].dt.normalize().astype(
|
||||
'datetime64[ns]',
|
||||
)
|
||||
expected.ix[3:5, 'timestamp'] += timedelta(days=1)
|
||||
expected.set_index(['timestamp', 'sid'], inplace=True)
|
||||
expected.index = pd.MultiIndex.from_product((
|
||||
expected.index.levels[0],
|
||||
finder.retrieve_all(expected.index.levels[1]),
|
||||
))
|
||||
assert_frame_equal(result, expected, check_dtype=False)
|
||||
|
||||
def test_id_macro_dataset(self):
|
||||
expr = bz.Data(self.macro_df, name='expr', dshape=self.macro_dshape)
|
||||
loader = BlazeLoader()
|
||||
|
||||
@@ -7,10 +7,12 @@ from unittest import TestCase
|
||||
|
||||
from nose_parameterized import parameterized
|
||||
from numpy import arange, dtype
|
||||
import pytz
|
||||
from six import PY3
|
||||
|
||||
from zipline.utils.preprocess import call, preprocess
|
||||
from zipline.utils.input_validation import (
|
||||
ensure_timezone,
|
||||
expect_element,
|
||||
expect_dtypes,
|
||||
expect_types,
|
||||
@@ -317,3 +319,31 @@ class PreprocessTestCase(TestCase):
|
||||
"or 'float64' for argument 'a', but got 'uint32' instead."
|
||||
).format(qualname=qualname(foo))
|
||||
self.assertEqual(e.exception.args[0], expected_message)
|
||||
|
||||
def test_ensure_timezone(self):
|
||||
@preprocess(tz=ensure_timezone)
|
||||
def f(tz):
|
||||
return tz
|
||||
|
||||
valid = {
|
||||
'utc',
|
||||
'EST',
|
||||
'US/Eastern',
|
||||
}
|
||||
invalid = {
|
||||
# unfortunatly, these are not actually timezones (yet)
|
||||
'ayy',
|
||||
'lmao',
|
||||
}
|
||||
|
||||
# test coercing from string
|
||||
for tz in valid:
|
||||
self.assertEqual(f(tz), pytz.timezone(tz))
|
||||
|
||||
# test pass through of tzinfo objects
|
||||
for tz in map(pytz.timezone, valid):
|
||||
self.assertEqual(f(tz), tz)
|
||||
|
||||
# test invalid timezone strings
|
||||
for tz in invalid:
|
||||
self.assertRaises(pytz.UnknownTimeZoneError, f, tz)
|
||||
|
||||
Reference in New Issue
Block a user