From 3f85af05e5a2da0d2f37f1428248a52f3de837a6 Mon Sep 17 00:00:00 2001 From: G_will Date: Tue, 15 Dec 2020 10:50:17 +0800 Subject: [PATCH] Refactor to Python3 style --- examples/benchmarks/TFT/expt_settings/configs.py | 2 +- examples/benchmarks/TFT/libs/tft_model.py | 6 +++--- qlib/contrib/backtest/__init__.py | 1 - qlib/contrib/model/pytorch_nn.py | 2 +- qlib/contrib/model/pytorch_sfm.py | 2 +- qlib/contrib/online/operator.py | 2 +- qlib/contrib/report/graph.py | 4 ++-- qlib/contrib/tuner/config.py | 6 +++--- qlib/contrib/tuner/pipeline.py | 2 +- qlib/contrib/tuner/tuner.py | 2 +- qlib/data/_libs/expanding.pyx | 2 +- qlib/data/_libs/rolling.pyx | 2 +- qlib/data/cache.py | 6 +++--- qlib/data/client.py | 2 +- qlib/log.py | 2 +- qlib/portfolio/optimizer.py | 2 +- qlib/utils/__init__.py | 2 +- 17 files changed, 23 insertions(+), 24 deletions(-) diff --git a/examples/benchmarks/TFT/expt_settings/configs.py b/examples/benchmarks/TFT/expt_settings/configs.py index 6aef0c395..62aa68c38 100644 --- a/examples/benchmarks/TFT/expt_settings/configs.py +++ b/examples/benchmarks/TFT/expt_settings/configs.py @@ -25,7 +25,7 @@ import os import data_formatters.qlib_Alpha158 -class ExperimentConfig(object): +class ExperimentConfig: """Defines experiment configs and paths to outputs. Attributes: diff --git a/examples/benchmarks/TFT/libs/tft_model.py b/examples/benchmarks/TFT/libs/tft_model.py index 658bae60f..b39f17825 100644 --- a/examples/benchmarks/TFT/libs/tft_model.py +++ b/examples/benchmarks/TFT/libs/tft_model.py @@ -320,7 +320,7 @@ class InterpretableMultiHeadAttention: return outputs, attn -class TFTDataCache(object): +class TFTDataCache: """Caches data for the TFT.""" _data_cache = {} @@ -348,7 +348,7 @@ class TFTDataCache(object): # TFT model definitions. -class TemporalFusionTransformer(object): +class TemporalFusionTransformer: """Defines Temporal Fusion Transformer. Attributes: @@ -972,7 +972,7 @@ class TemporalFusionTransformer(object): valid_quantiles = self.quantiles output_size = self.output_size - class QuantileLossCalculator(object): + class QuantileLossCalculator: """Computes the combined quantile loss for prespecified quantiles. Attributes: diff --git a/qlib/contrib/backtest/__init__.py b/qlib/contrib/backtest/__init__.py index 31746819c..6fcdf2142 100644 --- a/qlib/contrib/backtest/__init__.py +++ b/qlib/contrib/backtest/__init__.py @@ -1,7 +1,6 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -# -*- coding: utf-8 -*- from .order import Order from .account import Account from .position import Position diff --git a/qlib/contrib/model/pytorch_nn.py b/qlib/contrib/model/pytorch_nn.py index 308494443..a41eeabbb 100644 --- a/qlib/contrib/model/pytorch_nn.py +++ b/qlib/contrib/model/pytorch_nn.py @@ -296,7 +296,7 @@ class DNNModelPytorch(Model): self._fitted = True -class AverageMeter(object): +class AverageMeter: """Computes and stores the average and current value""" def __init__(self): diff --git a/qlib/contrib/model/pytorch_sfm.py b/qlib/contrib/model/pytorch_sfm.py index 15d945c89..ae175a202 100644 --- a/qlib/contrib/model/pytorch_sfm.py +++ b/qlib/contrib/model/pytorch_sfm.py @@ -464,7 +464,7 @@ class SFM(Model): return pd.Series(np.concatenate(preds), index=index) -class AverageMeter(object): +class AverageMeter: """Computes and stores the average and current value""" def __init__(self): diff --git a/qlib/contrib/online/operator.py b/qlib/contrib/online/operator.py index a00e17d40..c8b44f578 100644 --- a/qlib/contrib/online/operator.py +++ b/qlib/contrib/online/operator.py @@ -21,7 +21,7 @@ from .executor import SimulatorExecutor from .executor import save_score_series, load_score_series -class Operator(object): +class Operator: def __init__(self, client: str): """ Parameters diff --git a/qlib/contrib/report/graph.py b/qlib/contrib/report/graph.py index 3fa688d36..70e382fb1 100644 --- a/qlib/contrib/report/graph.py +++ b/qlib/contrib/report/graph.py @@ -17,7 +17,7 @@ from plotly.figure_factory import create_distplot from ...utils import get_module_by_module_path -class BaseGraph(object): +class BaseGraph: """""" _name = None @@ -204,7 +204,7 @@ class HistogramGraph(BaseGraph): return _data -class SubplotsGraph(object): +class SubplotsGraph: """Create subplots same as df.plot(subplots=True) Simple package for `plotly.tools.subplots` diff --git a/qlib/contrib/tuner/config.py b/qlib/contrib/tuner/config.py index 4825ca092..f23d1b874 100644 --- a/qlib/contrib/tuner/config.py +++ b/qlib/contrib/tuner/config.py @@ -6,7 +6,7 @@ import copy import os -class TunerConfigManager(object): +class TunerConfigManager: def __init__(self, config_path): if not config_path: @@ -27,7 +27,7 @@ class TunerConfigManager(object): self.qlib_client_config = config.get("qlib_client", dict()) -class PipelineExperimentConfig(object): +class PipelineExperimentConfig: def __init__(self, config, TUNER_CONFIG_MANAGER): """ :param config: The config dict for tuner experiment @@ -53,7 +53,7 @@ class PipelineExperimentConfig(object): yaml.dump(TUNER_CONFIG_MANAGER.config, fp) -class OptimizationConfig(object): +class OptimizationConfig: def __init__(self, config, TUNER_CONFIG_MANAGER): self.report_type = config.get("report_type", "pred_long") diff --git a/qlib/contrib/tuner/pipeline.py b/qlib/contrib/tuner/pipeline.py index 3a76d071d..ee92db529 100644 --- a/qlib/contrib/tuner/pipeline.py +++ b/qlib/contrib/tuner/pipeline.py @@ -11,7 +11,7 @@ from ...log import get_module_logger, TimeInspector from ...utils import get_module_by_module_path -class Pipeline(object): +class Pipeline: GLOBAL_BEST_PARAMS_NAME = "global_best_params.json" diff --git a/qlib/contrib/tuner/tuner.py b/qlib/contrib/tuner/tuner.py index 8da40bc69..2ce957859 100644 --- a/qlib/contrib/tuner/tuner.py +++ b/qlib/contrib/tuner/tuner.py @@ -19,7 +19,7 @@ from hyperopt import fmin, tpe from hyperopt import STATUS_OK, STATUS_FAIL -class Tuner(object): +class Tuner: def __init__(self, tuner_config, optim_config): self.logger = get_module_logger("Tuner", sh_level=logging.INFO) diff --git a/qlib/data/_libs/expanding.pyx b/qlib/data/_libs/expanding.pyx index 47bc49610..6c27c07eb 100644 --- a/qlib/data/_libs/expanding.pyx +++ b/qlib/data/_libs/expanding.pyx @@ -8,7 +8,7 @@ from libc.math cimport sqrt, isnan, NAN from libcpp.vector cimport vector -cdef class Expanding(object): +cdef class Expanding: """1-D array expanding""" cdef vector[double] barv cdef int na_count diff --git a/qlib/data/_libs/rolling.pyx b/qlib/data/_libs/rolling.pyx index 37d27ffa4..a18679a99 100644 --- a/qlib/data/_libs/rolling.pyx +++ b/qlib/data/_libs/rolling.pyx @@ -8,7 +8,7 @@ from libc.math cimport sqrt, isnan, NAN from libcpp.deque cimport deque -cdef class Rolling(object): +cdef class Rolling: """1-D array rolling""" cdef int window cdef deque[double] barv diff --git a/qlib/data/cache.py b/qlib/data/cache.py index 3fab2b527..d53f578b1 100644 --- a/qlib/data/cache.py +++ b/qlib/data/cache.py @@ -68,7 +68,7 @@ class MemCacheUnit(OrderedDict): self.popitem(last=False) -class MemCache(object): +class MemCache: """Memory cache.""" def __init__(self, mem_cache_size_limit=None, limit_type="length"): @@ -140,7 +140,7 @@ class MemCacheExpire: return value, expire -class CacheUtils(object): +class CacheUtils: LOCK_ID = "QLIB" @staticmethod @@ -224,7 +224,7 @@ class CacheUtils(object): current_cache_wlock.release() -class BaseProviderCache(object): +class BaseProviderCache: """Provider cache base class""" def __init__(self, provider): diff --git a/qlib/data/client.py b/qlib/data/client.py index 65a830f20..5244a7e45 100644 --- a/qlib/data/client.py +++ b/qlib/data/client.py @@ -12,7 +12,7 @@ from ..log import get_module_logger import pickle -class Client(object): +class Client: """A client class Provide the connection tool functions for ClientProvider. diff --git a/qlib/log.py b/qlib/log.py index 422a4c00b..6553dcb11 100644 --- a/qlib/log.py +++ b/qlib/log.py @@ -36,7 +36,7 @@ def get_module_logger(module_name, level=None): return module_logger -class TimeInspector(object): +class TimeInspector: timer_logger = get_module_logger("timer", level=logging.WARNING) diff --git a/qlib/portfolio/optimizer.py b/qlib/portfolio/optimizer.py index 534a66e2d..0e7d27254 100644 --- a/qlib/portfolio/optimizer.py +++ b/qlib/portfolio/optimizer.py @@ -9,7 +9,7 @@ import scipy.optimize as so from typing import Optional, Union, Callable, List -class PortfolioOptimizer(object): +class PortfolioOptimizer: """Portfolio Optimizer The following optimization algorithms are supported: diff --git a/qlib/utils/__init__.py b/qlib/utils/__init__.py index ab67b67e3..ddc17c478 100644 --- a/qlib/utils/__init__.py +++ b/qlib/utils/__init__.py @@ -686,7 +686,7 @@ def flatten_dict(d, parent_key="", sep="."): #################### Wrapper ##################### -class Wrapper(object): +class Wrapper: """Wrapper class for anything that needs to set up during qlib.init""" def __init__(self):