diff --git a/qlib/data/dataset/handler.py b/qlib/data/dataset/handler.py index 6ead332d2..78d19d005 100644 --- a/qlib/data/dataset/handler.py +++ b/qlib/data/dataset/handler.py @@ -62,9 +62,11 @@ class DataHandler(Serializable): # Setup data loader 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, - accept_types=DataLoader) + + self.data_loader = init_instance_by_config( + 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.start_time = start_time diff --git a/qlib/utils/__init__.py b/qlib/utils/__init__.py index 900d9e115..8d16798d6 100644 --- a/qlib/utils/__init__.py +++ b/qlib/utils/__init__.py @@ -195,22 +195,24 @@ def get_cls_kwargs(config: Union[dict, str], module) -> (type, dict): 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: """ get initialized instance with config Parameters ---------- - config : Union[str, dict] + config : Union[str, dict, object] dict example. - { - 'class': 'ClassName', - 'kwargs': dict, # It is optional. {} will be used if not given - 'model_path': path, # It is optional if module is given - } + { + 'class': 'ClassName', + 'kwargs': dict, # It is optional. {} will be used if not given + 'model_path': path, # It is optional if module is given + } 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 Optional. It should be a python module. NOTE: the "module_path" will be override by `module` arguments