mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-13 07:46:53 +08:00
add handler pickle attr, enhance init_instance_by_config
This commit is contained in:
@@ -124,7 +124,8 @@ class SDFLoc:
|
|||||||
if isinstance(args, str):
|
if isinstance(args, str):
|
||||||
return self._sdf[args]
|
return self._sdf[args]
|
||||||
elif isinstance(args, (tuple, list)):
|
elif isinstance(args, (tuple, list)):
|
||||||
return SepDataFrame({k: self._sdf[k] for k in args}, join=self.join)
|
new_df_dict = {k: self._sdf[k] for k in args}
|
||||||
|
return SepDataFrame(new_df_dict, join=self.join if self.join in args else args[0])
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(f"This type of input is not supported")
|
raise NotImplementedError(f"This type of input is not supported")
|
||||||
elif self.axis == 0:
|
elif self.axis == 0:
|
||||||
|
|||||||
@@ -644,6 +644,12 @@ class DataHandlerLP(DataHandler):
|
|||||||
new_hd: DataHandlerLP = object.__new__(DataHandlerLP)
|
new_hd: DataHandlerLP = object.__new__(DataHandlerLP)
|
||||||
new_hd.from_cast = True # add a mark for the casted instance
|
new_hd.from_cast = True # add a mark for the casted instance
|
||||||
|
|
||||||
for key in list(DataHandlerLP.ATTR_MAP.values()) + ["instruments", "start_time", "end_time", "fetch_orig"]:
|
for key in list(DataHandlerLP.ATTR_MAP.values()) + [
|
||||||
|
"instruments",
|
||||||
|
"start_time",
|
||||||
|
"end_time",
|
||||||
|
"fetch_orig",
|
||||||
|
"drop_raw",
|
||||||
|
]:
|
||||||
setattr(new_hd, key, getattr(handler, key, None))
|
setattr(new_hd, key, getattr(handler, key, None))
|
||||||
return new_hd
|
return new_hd
|
||||||
|
|||||||
@@ -199,6 +199,7 @@ def get_callable_kwargs(config: Union[dict, str], default_module: Union[str, Mod
|
|||||||
----------
|
----------
|
||||||
config : [dict, str]
|
config : [dict, str]
|
||||||
similar to config
|
similar to config
|
||||||
|
please refer to the doc of init_instance_by_config
|
||||||
|
|
||||||
default_module : Python module or str
|
default_module : Python module or str
|
||||||
It should be a python module to load the class type
|
It should be a python module to load the class type
|
||||||
@@ -219,9 +220,12 @@ def get_callable_kwargs(config: Union[dict, str], default_module: Union[str, Mod
|
|||||||
_callable = config["class"] # the class type itself is passed in
|
_callable = config["class"] # the class type itself is passed in
|
||||||
kwargs = config.get("kwargs", {})
|
kwargs = config.get("kwargs", {})
|
||||||
elif isinstance(config, str):
|
elif isinstance(config, str):
|
||||||
module = get_module_by_module_path(default_module)
|
# a.b.c.ClassName
|
||||||
|
*m_path, cls = config.split(".")
|
||||||
|
m_path = ".".join(m_path)
|
||||||
|
module = get_module_by_module_path(default_module if m_path == "" else m_path)
|
||||||
|
|
||||||
_callable = getattr(module, config)
|
_callable = getattr(module, cls)
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(f"This type of input is not supported")
|
raise NotImplementedError(f"This type of input is not supported")
|
||||||
@@ -260,7 +264,9 @@ def init_instance_by_config(
|
|||||||
1) specify a pickle object
|
1) specify a pickle object
|
||||||
- path like 'file:///<path to pickle file>/obj.pkl'
|
- path like 'file:///<path to pickle file>/obj.pkl'
|
||||||
2) specify a class name
|
2) specify a class name
|
||||||
- "ClassName": getattr(module, config)() will be used.
|
- "ClassName": getattr(module, "ClassName")() will be used.
|
||||||
|
3) specify module path with class name
|
||||||
|
- "a.b.c.ClassName" getattr(<a.b.c.module>, "ClassName")() will be used.
|
||||||
object example:
|
object example:
|
||||||
instance of accept_types
|
instance of accept_types
|
||||||
default_module : Python module
|
default_module : Python module
|
||||||
|
|||||||
Reference in New Issue
Block a user