From dbabf6880b338329e9d0bab3e1fe4d5b08aedd36 Mon Sep 17 00:00:00 2001 From: you-n-g Date: Wed, 28 Jul 2021 14:37:43 +0800 Subject: [PATCH] sort index after loader make sure the fetch method is based on a index-sorted pd.DataFrame --- qlib/data/dataset/handler.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qlib/data/dataset/handler.py b/qlib/data/dataset/handler.py index c6338832a5e..b823728fb73 100644 --- a/qlib/data/dataset/handler.py +++ b/qlib/data/dataset/handler.py @@ -18,6 +18,7 @@ from ...utils import parse_config, transform_end_date, init_instance_by_config from ...utils.serial import Serializable from .utils import fetch_df_by_index +from ...utils import lazy_sort_index from pathlib import Path from .loader import DataLoader @@ -146,7 +147,8 @@ def setup_data(self, enable_cache: bool = False): # Setup data. # _data may be with multiple column index level. The outer level indicates the feature set name with TimeInspector.logt("Loading data"): - self._data = self.data_loader.load(self.instruments, self.start_time, self.end_time) + # make sure the fetch method is based on a index-sorted pd.DataFrame + self._data = lazy_sort_index(self.data_loader.load(self.instruments, self.start_time, self.end_time)) # TODO: cache CS_ALL = "__all" # return all columns with single-level index column