mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-02 10:31:00 +08:00
Fix some warnings in log.py. (#805)
* Fix some warnings in log.py. * Fix typo and using black format. * Fix black. * Rename dict_ to attrs
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
About the configs
|
||||
=================
|
||||
|
||||
The config will based on _default_config.
|
||||
The config will be based on _default_config.
|
||||
Two modes are supported
|
||||
- client
|
||||
- server
|
||||
@@ -28,7 +28,7 @@ if TYPE_CHECKING:
|
||||
|
||||
class Config:
|
||||
def __init__(self, default_conf):
|
||||
self.__dict__["_default_config"] = copy.deepcopy(default_conf) # avoiding conflictions with __getattr__
|
||||
self.__dict__["_default_config"] = copy.deepcopy(default_conf) # avoiding conflicts with __getattr__
|
||||
self.reset()
|
||||
|
||||
def __getitem__(self, key):
|
||||
@@ -271,7 +271,11 @@ class QlibConfig(Config):
|
||||
self._registered = False
|
||||
|
||||
class DataPathManager:
|
||||
def __init__(self, provider_uri: Union[str, Path, dict], mount_path: Union[str, Path, dict]):
|
||||
def __init__(
|
||||
self,
|
||||
provider_uri: Union[str, Path, dict],
|
||||
mount_path: Union[str, Path, dict],
|
||||
):
|
||||
self.provider_uri = provider_uri
|
||||
self.mount_path = mount_path
|
||||
|
||||
@@ -360,10 +364,10 @@ class QlibConfig(Config):
|
||||
"""
|
||||
configure qlib based on the input parameters
|
||||
|
||||
The configure will act like a dictionary.
|
||||
The configuration will act like a dictionary.
|
||||
|
||||
Normally, it literally replace the value according to the keys.
|
||||
However, sometimes it is hard for users to set the config when the configure is nested and complicated
|
||||
Normally, it literally is replaced the value according to the keys.
|
||||
However, sometimes it is hard for users to set the config when the configuration is nested and complicated
|
||||
|
||||
So this API provides some special parameters for users to set the keys in a more convenient way.
|
||||
- region: REG_CN, REG_US
|
||||
|
||||
13
qlib/log.py
13
qlib/log.py
@@ -13,12 +13,12 @@ from .config import C
|
||||
|
||||
|
||||
class MetaLogger(type):
|
||||
def __new__(cls, name, bases, dict):
|
||||
def __new__(mcs, name, bases, attrs):
|
||||
wrapper_dict = logging.Logger.__dict__.copy()
|
||||
for key in wrapper_dict:
|
||||
if key not in dict and key != "__reduce__":
|
||||
dict[key] = wrapper_dict[key]
|
||||
return type.__new__(cls, name, bases, dict)
|
||||
if key not in attrs and key != "__reduce__":
|
||||
attrs[key] = wrapper_dict[key]
|
||||
return type.__new__(mcs, name, bases, attrs)
|
||||
|
||||
|
||||
class QlibLogger(metaclass=MetaLogger):
|
||||
@@ -48,7 +48,7 @@ class QlibLogger(metaclass=MetaLogger):
|
||||
return self.logger.__getattribute__(name)
|
||||
|
||||
|
||||
def get_module_logger(module_name, level: Optional[int] = None) -> logging.Logger:
|
||||
def get_module_logger(module_name, level: Optional[int] = None) -> QlibLogger:
|
||||
"""
|
||||
Get a logger for a specific module.
|
||||
|
||||
@@ -107,7 +107,7 @@ class TimeInspector:
|
||||
"""
|
||||
Get last time mark from stack, calculate time diff with current time, and log time diff and info.
|
||||
:param info: str
|
||||
Info that will be log into stdout.
|
||||
Info that will be logged into stdout.
|
||||
"""
|
||||
cost_time = time() - cls.time_marks.pop()
|
||||
cls.timer_logger.info("Time cost: {0:.3f}s | {1}".format(cost_time, info))
|
||||
@@ -146,6 +146,7 @@ def set_log_with_config(log_config: Dict[Text, Any]):
|
||||
|
||||
class LogFilter(logging.Filter):
|
||||
def __init__(self, param=None):
|
||||
super().__init__()
|
||||
self.param = param
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -81,7 +81,14 @@ class QlibRecorder:
|
||||
self.end_exp(Recorder.STATUS_FI)
|
||||
|
||||
def start_exp(
|
||||
self, *, experiment_id=None, experiment_name=None, recorder_id=None, recorder_name=None, uri=None, resume=False
|
||||
self,
|
||||
*,
|
||||
experiment_id=None,
|
||||
experiment_name=None,
|
||||
recorder_id=None,
|
||||
recorder_name=None,
|
||||
uri=None,
|
||||
resume=False,
|
||||
):
|
||||
"""
|
||||
Lower level method for starting an experiment. When use this method, one should end the experiment manually
|
||||
@@ -289,7 +296,10 @@ class QlibRecorder:
|
||||
An experiment instance with given id or name.
|
||||
"""
|
||||
return self.exp_manager.get_exp(
|
||||
experiment_id=experiment_id, experiment_name=experiment_name, create=create, start=False
|
||||
experiment_id=experiment_id,
|
||||
experiment_name=experiment_name,
|
||||
create=create,
|
||||
start=False,
|
||||
)
|
||||
|
||||
def delete_exp(self, experiment_id=None, experiment_name=None):
|
||||
@@ -355,7 +365,12 @@ class QlibRecorder:
|
||||
self.exp_manager.set_uri(prev_uri)
|
||||
|
||||
def get_recorder(
|
||||
self, *, recorder_id=None, recorder_name=None, experiment_id=None, experiment_name=None
|
||||
self,
|
||||
*,
|
||||
recorder_id=None,
|
||||
recorder_name=None,
|
||||
experiment_id=None,
|
||||
experiment_name=None,
|
||||
) -> Recorder:
|
||||
"""
|
||||
Method for retrieving a recorder.
|
||||
|
||||
Reference in New Issue
Block a user