Skip to content

Commit 4d621bf

Browse files
authored
fix pkl file not loading in StaticDataLoader (#1896)
* fix pkl file not loading in StaticDataLoader * resolve hard code * resolve hard code
1 parent 82f1ef2 commit 4d621bf

File tree

9 files changed

+20
-16
lines changed

9 files changed

+20
-16
lines changed

examples/data_demo/data_cache_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33
"""
4-
The motivation of this demo
5-
- To show the data modules of Qlib is Serializable, users can dump processed data to disk to avoid duplicated data preprocessing
4+
The motivation of this demo
5+
- To show the data modules of Qlib is Serializable, users can dump processed data to disk to avoid duplicated data preprocessing
66
"""
77

88
from copy import deepcopy

examples/data_demo/data_mem_resuse_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33
"""
4-
The motivation of this demo
5-
- To show the data modules of Qlib is Serializable, users can dump processed data to disk to avoid duplicated data preprocessing
4+
The motivation of this demo
5+
- To show the data modules of Qlib is Serializable, users can dump processed data to disk to avoid duplicated data preprocessing
66
"""
77

88
from copy import deepcopy

examples/orderbook_data/create_dataset.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33
"""
4-
NOTE:
5-
- This scripts is a demo to import example data import Qlib
6-
- !!!!!!!!!!!!!!!TODO!!!!!!!!!!!!!!!!!!!:
7-
- Its structure is not well designed and very ugly, your contribution is welcome to make importing dataset easier
4+
NOTE:
5+
- This scripts is a demo to import example data import Qlib
6+
- !!!!!!!!!!!!!!!TODO!!!!!!!!!!!!!!!!!!!:
7+
- Its structure is not well designed and very ugly, your contribution is welcome to make importing dataset easier
88
"""
99
from datetime import date, datetime as dt
1010
import os

examples/workflow_by_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33
"""
4-
Qlib provides two kinds of interfaces.
4+
Qlib provides two kinds of interfaces.
55
(1) Users could define the Quant research workflow by a simple configuration.
66
(2) Qlib is designed in a modularized way and supports creating research workflow by code just like building blocks.
77

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ dependencies = [
4444
"matplotlib",
4545
"jupyter",
4646
"nbconvert",
47+
"pyarrow",
4748
]
4849

4950
[project.optional-dependencies]

qlib/contrib/torch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33
"""
4-
This module is not a necessary part of Qlib.
5-
They are just some tools for convenience
6-
It is should not imported into the core part of qlib
4+
This module is not a necessary part of Qlib.
5+
They are just some tools for convenience
6+
It is should not imported into the core part of qlib
77
"""
88
import torch
99
import numpy as np

qlib/data/dataset/loader.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,11 @@ def _maybe_load_raw_data(self):
279279
)
280280
self._data.sort_index(inplace=True)
281281
elif isinstance(self._config, (str, Path)):
282-
with Path(self._config).open("rb") as f:
283-
self._data = pickle.load(f)
282+
if str(self._config).strip().endswith(".parquet"):
283+
self._data = pd.read_parquet(self._config, engine="pyarrow")
284+
else:
285+
with Path(self._config).open("rb") as f:
286+
self._data = pickle.load(f)
284287
elif isinstance(self._config, pd.DataFrame):
285288
self._data = self._config
286289

qlib/rl/trainer/trainer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def fit(self, vessel: TrainingVesselBase, ckpt_path: Path | None = None) -> None
200200

201201
if ckpt_path is not None:
202202
_logger.info("Resuming states from %s", str(ckpt_path))
203-
self.load_state_dict(torch.load(ckpt_path))
203+
self.load_state_dict(torch.load(ckpt_path, weights_only=False))
204204
else:
205205
self.initialize()
206206

tests/rl/test_trainer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def test_trainer_checkpoint():
194194
assert (output_dir / "002.pth").exists()
195195
assert os.readlink(output_dir / "latest.pth") == str(output_dir / "002.pth")
196196

197-
trainer.load_state_dict(torch.load(output_dir / "001.pth"))
197+
trainer.load_state_dict(torch.load(output_dir / "001.pth", weights_only=False))
198198
assert trainer.current_iter == 1
199199
assert trainer.current_episode == 100
200200

0 commit comments

Comments
 (0)