From 62d6720c0d437385f125bf1a387e163f3cb037c0 Mon Sep 17 00:00:00 2001 From: YeewahChan Date: Mon, 3 Jun 2024 15:32:06 +0800 Subject: [PATCH] Fix TSDataSampler Slicing Bug #1716 --- qlib/data/dataset/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qlib/data/dataset/__init__.py b/qlib/data/dataset/__init__.py index 2c3c12c0a7..6d985d2b20 100644 --- a/qlib/data/dataset/__init__.py +++ b/qlib/data/dataset/__init__.py @@ -627,7 +627,7 @@ def __getitem__(self, idx: Union[int, Tuple[object, str], List[int]]): indices = np.nan_to_num(indices.astype(np.float64), nan=self.nan_idx).astype(int) if (np.diff(indices) == 1).all(): # slicing instead of indexing for speeding up. - if indices[0] < 0 : + if indices[0] == -1 : data = self.data_arr[0 : indices[-1] + 1] # Prepend nan values to the data to match the step_len data = np.concatenate([np.full((self.step_len - len(data), *data.shape[1:]), np.nan), data])