1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-18 18:04:31 +08:00

fix data_loader dict type bug

This commit is contained in:
Young
2020-11-10 01:45:34 +00:00
parent b1c6b216fe
commit 21a24f9893
2 changed files with 15 additions and 11 deletions

View File

@@ -62,9 +62,11 @@ class DataHandler(Serializable):
# Setup data loader # Setup data loader
assert data_loader is not None # to make start_time end_time could have None default value assert data_loader is not None # to make start_time end_time could have None default value
self.data_loader = init_instance_by_config(data_loader,
None if 'module_path' in data_loader else data_loader_module, self.data_loader = init_instance_by_config(
accept_types=DataLoader) data_loader,
None if (isinstance(data_loader, dict) and 'module_path' in data_loader) else data_loader_module,
accept_types=DataLoader)
self.instruments = instruments self.instruments = instruments
self.start_time = start_time self.start_time = start_time

View File

@@ -195,22 +195,24 @@ def get_cls_kwargs(config: Union[dict, str], module) -> (type, dict):
def init_instance_by_config( def init_instance_by_config(
config: Union[str, dict], module=None, accept_types: Union[type, Tuple[type]] = tuple([]), **kwargs config: Union[str, dict, object], module=None, accept_types: Union[type, Tuple[type]] = tuple([]), **kwargs
) -> object: ) -> object:
""" """
get initialized instance with config get initialized instance with config
Parameters Parameters
---------- ----------
config : Union[str, dict] config : Union[str, dict, object]
dict example. dict example.
{ {
'class': 'ClassName', 'class': 'ClassName',
'kwargs': dict, # It is optional. {} will be used if not given 'kwargs': dict, # It is optional. {} will be used if not given
'model_path': path, # It is optional if module is given 'model_path': path, # It is optional if module is given
} }
str example. str example.
"ClassName": getattr(module, config)() will be used. "ClassName": getattr(module, config)() will be used.
object example:
instance of accept_types
module : Python module module : Python module
Optional. It should be a python module. Optional. It should be a python module.
NOTE: the "module_path" will be override by `module` arguments NOTE: the "module_path" will be override by `module` arguments