1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-06-06 05:51:17 +08:00

fix: handler_mod func don't work when dealing None end date (#2068)

* [fix] handler_mod func don't work when dealing None end date

* refactor: avoid deep access by extracting handler_kwargs and using get(end_time)

---------

Co-authored-by: Linlang <Lv.Linlang@hotmail.com>
This commit is contained in:
Dred
2025-12-27 14:44:10 +08:00
committed by GitHub
parent cb285bccac
commit 3472e82d5c

View File

@@ -106,15 +106,13 @@ def handler_mod(task: dict, rolling_gen):
rg (RollingGen): an instance of RollingGen
"""
try:
interval = rolling_gen.ta.cal_interval(
task["dataset"]["kwargs"]["handler"]["kwargs"]["end_time"],
task["dataset"]["kwargs"]["segments"][rolling_gen.test_key][1],
)
# if end_time < the end of test_segments, then change end_time to allow load more data
if interval < 0:
task["dataset"]["kwargs"]["handler"]["kwargs"]["end_time"] = copy.deepcopy(
task["dataset"]["kwargs"]["segments"][rolling_gen.test_key][1]
)
handler_kwargs = task["dataset"]["kwargs"]["handler"]["kwargs"]
handler_end_time = handler_kwargs.get("end_time")
test_seg_end_time = task["dataset"]["kwargs"]["segments"][rolling_gen.test_key][1]
# if the end of test_segments is None (open-ended segment, i.e., "until now") or end_time < the end of test_segments,
# then change end_time to allow load more data
if test_seg_end_time is None or rolling_gen.ta.cal_interval(handler_end_time, test_seg_end_time) < 0:
handler_kwargs["end_time"] = copy.deepcopy(test_seg_end_time)
except KeyError:
# Maybe dataset do not have handler, then do nothing.
pass