From 946c9392a1eb6bbe1131c4da60d41776996d6776 Mon Sep 17 00:00:00 2001 From: bxdd Date: Thu, 1 Jul 2021 18:01:42 +0000 Subject: [PATCH] support check_transform_proc module_path --- examples/highfreq/highfreq_handler.py | 20 ++++---------------- examples/highfreq/highfreq_ops.py | 2 +- examples/highfreq/workflow.py | 2 +- qlib/contrib/data/handler.py | 6 ++++-- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/examples/highfreq/highfreq_handler.py b/examples/highfreq/highfreq_handler.py index d35650514..111fe57bf 100644 --- a/examples/highfreq/highfreq_handler.py +++ b/examples/highfreq/highfreq_handler.py @@ -1,7 +1,6 @@ from qlib.data.dataset.handler import DataHandler, DataHandlerLP -from qlib.data.dataset.processor import Processor -from qlib.utils import get_cls_kwargs -from qlib.log import TimeInspector +from qlib.contrib.data.handler import check_transform_proc + class HighFreqHandler(DataHandlerLP): @@ -16,20 +15,9 @@ class HighFreqHandler(DataHandlerLP): fit_end_time=None, drop_raw=True, ): - def check_transform_proc(proc_l): - new_l = [] - for p in proc_l: - p["kwargs"].update( - { - "fit_start_time": fit_start_time, - "fit_end_time": fit_end_time, - } - ) - new_l.append(p) - return new_l - infer_processors = check_transform_proc(infer_processors) - learn_processors = check_transform_proc(learn_processors) + infer_processors = check_transform_proc(infer_processors, fit_start_time, fit_end_time) + learn_processors = check_transform_proc(learn_processors, fit_start_time, fit_end_time) data_loader = { "class": "QlibDataLoader", diff --git a/examples/highfreq/highfreq_ops.py b/examples/highfreq/highfreq_ops.py index 66a084f9f..ef784b34c 100644 --- a/examples/highfreq/highfreq_ops.py +++ b/examples/highfreq/highfreq_ops.py @@ -26,7 +26,7 @@ def get_calendar_day(freq="day", future=False): if flag in H["c"]: _calendar = H["c"][flag] else: - _calendar = np.array(list(map(lambda x: x.date(), Cal.load_calendar(freq, future)))) + _calendar = np.array(list(map(lambda x: pd.Timestamp(x.date()), Cal.load_calendar(freq, future)))) H["c"][flag] = _calendar return _calendar diff --git a/examples/highfreq/workflow.py b/examples/highfreq/workflow.py index 7bf5fd09a..e9278cdb1 100644 --- a/examples/highfreq/workflow.py +++ b/examples/highfreq/workflow.py @@ -33,7 +33,7 @@ class HighfreqWorkflow: "fit_start_time": start_time, "fit_end_time": train_end_time, "instruments": MARKET, - "infer_processors": [{"class": "HighFreqNorm", "module_path": "highfreq_processor", "kwargs": {}}], + "infer_processors": [{"class": "HighFreqNorm", "module_path": "highfreq_processor"}], } DATA_HANDLER_CONFIG1 = { "start_time": start_time, diff --git a/qlib/contrib/data/handler.py b/qlib/contrib/data/handler.py index be2016ea3..b22741f4a 100644 --- a/qlib/contrib/data/handler.py +++ b/qlib/contrib/data/handler.py @@ -26,8 +26,10 @@ def check_transform_proc(proc_l, fit_start_time, fit_end_time): "fit_end_time": fit_end_time, } ) - # FIXME: the `module_path` parameter is missed. - new_l.append({"class": klass.__name__, "kwargs": pkwargs}) + proc_config = {"class": klass.__name__, "kwargs": pkwargs} + if isinstance(p, dict) and "module_path" in p: + proc_config["module_path"] = p["module_path"] + new_l.append(proc_config) else: new_l.append(p) return new_l