Skip to content

Commit

Permalink
fix tra dataset bug (#1050)
Browse files Browse the repository at this point in the history
  • Loading branch information
you-n-g authored Apr 15, 2022
1 parent e1271a8 commit 41447f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions examples/benchmarks/TRA/src/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import numpy as np
import pandas as pd

from qlib.utils import init_instance_by_config
from qlib.data.dataset import DatasetH, DataHandler
from qlib.data.dataset import DatasetH


device = "cuda" if torch.cuda.is_available() else "cpu"
Expand Down Expand Up @@ -95,7 +94,7 @@ def __init__(
shuffle=True,
pin_memory=False,
drop_last=False,
**kwargs
**kwargs,
):

assert horizon > 0, "please specify `horizon` to avoid data leakage"
Expand Down Expand Up @@ -150,8 +149,15 @@ def setup_data(self, handler_kwargs: dict = None, **kwargs):

def _prepare_seg(self, slc, **kwargs):
fn = _get_date_parse_fn(self._index[0][1])
start_date = fn(slc.start)
end_date = fn(slc.stop)

if isinstance(slc, slice):
start, stop = slc.start, slc.stop
elif isinstance(slc, (list, tuple)):
start, stop = slc
else:
raise NotImplementedError(f"This type of input is not supported")
start_date = fn(start)
end_date = fn(stop)
obj = copy.copy(self) # shallow copy
# NOTE: Seriable will disable copy `self._data` so we manually assign them here
obj._data = self._data
Expand Down
1 change: 1 addition & 0 deletions qlib/data/dataset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def _prepare_seg(self, slc, **kwargs):
Parameters
----------
slc : please refer to the docs of `prepare`
NOTE: it may not be an instance of slice. It may be a segment of `segments` from `def prepare`
"""
if hasattr(self, "fetch_kwargs"):
return self.handler.fetch(slc, **kwargs, **self.fetch_kwargs)
Expand Down

0 comments on commit 41447f3

Please sign in to comment.