mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-12 23:36:54 +08:00
Fix pylint (#888)
* add_pylint_to_workflow * fix-pylint * fix_pylinterror * fix-issue
This commit is contained in:
@@ -52,7 +52,6 @@ class Dataset(Serializable):
|
||||
|
||||
- User prepare data for model based on previous status.
|
||||
"""
|
||||
pass
|
||||
|
||||
def prepare(self, **kwargs) -> object:
|
||||
"""
|
||||
@@ -68,7 +67,6 @@ class Dataset(Serializable):
|
||||
object:
|
||||
return the object
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class DatasetH(Dataset):
|
||||
@@ -348,7 +346,7 @@ class TSDataSampler:
|
||||
flt_data = flt_data.reindex(self.data_index).fillna(False).astype(np.bool)
|
||||
self.flt_data = flt_data.values
|
||||
self.idx_map = self.flt_idx_map(self.flt_data, self.idx_map)
|
||||
self.data_index = self.data_index[np.where(self.flt_data == True)[0]]
|
||||
self.data_index = self.data_index[np.where(self.flt_data is True)[0]]
|
||||
self.idx_map = self.idx_map2arr(self.idx_map)
|
||||
|
||||
self.start_idx, self.end_idx = self.data_index.slice_locs(
|
||||
|
||||
@@ -2,24 +2,16 @@
|
||||
# Licensed under the MIT License.
|
||||
|
||||
# coding=utf-8
|
||||
import abc
|
||||
import bisect
|
||||
import logging
|
||||
import warnings
|
||||
from inspect import getfullargspec
|
||||
from typing import Callable, Union, Tuple, List, Iterator, Optional
|
||||
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
from ...log import get_module_logger, TimeInspector
|
||||
from ...data import D
|
||||
from ...config import C
|
||||
from ...utils import parse_config, transform_end_date, init_instance_by_config
|
||||
from ...utils import init_instance_by_config
|
||||
from ...utils.serial import Serializable
|
||||
from .utils import fetch_df_by_index, fetch_df_by_col
|
||||
from ...utils import lazy_sort_index
|
||||
from pathlib import Path
|
||||
from .loader import DataLoader
|
||||
|
||||
from . import processor as processor_module
|
||||
@@ -228,7 +220,7 @@ class DataHandler(Serializable):
|
||||
proc_func: Callable = None,
|
||||
):
|
||||
# This method is extracted for sharing in subclasses
|
||||
from .storage import BaseHandlerStorage
|
||||
from .storage import BaseHandlerStorage # pylint: disable=C0415
|
||||
|
||||
# Following conflictions may occurs
|
||||
# - Does [20200101", "20210101"] mean selecting this slice or these two days?
|
||||
@@ -627,7 +619,6 @@ class DataHandlerLP(DataHandler):
|
||||
-------
|
||||
pd.DataFrame:
|
||||
"""
|
||||
from .storage import BaseHandlerStorage
|
||||
|
||||
return self._fetch_data(
|
||||
data_storage=self._get_df_by_key(data_key),
|
||||
|
||||
@@ -51,7 +51,6 @@ class DataLoader(abc.ABC):
|
||||
pd.DataFrame:
|
||||
data load from the under layer source
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class DLWParser(DataLoader):
|
||||
@@ -129,7 +128,6 @@ class DLWParser(DataLoader):
|
||||
pd.DataFrame:
|
||||
the queried dataframe.
|
||||
"""
|
||||
pass
|
||||
|
||||
def load(self, instruments=None, start_time=None, end_time=None) -> pd.DataFrame:
|
||||
if self.is_group:
|
||||
@@ -308,7 +306,7 @@ class DataLoaderDH(DataLoader):
|
||||
is_group will be used to describe whether the key of handler_config is group
|
||||
|
||||
"""
|
||||
from qlib.data.dataset.handler import DataHandler
|
||||
from qlib.data.dataset.handler import DataHandler # pylint: disable=C0415
|
||||
|
||||
if is_group:
|
||||
self.handlers = {
|
||||
|
||||
@@ -42,7 +42,6 @@ class Processor(Serializable):
|
||||
processor, i.e. `df`.
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def __call__(self, df: pd.DataFrame):
|
||||
@@ -57,7 +56,6 @@ class Processor(Serializable):
|
||||
df : pd.DataFrame
|
||||
The raw_df of handler or result from previous processor.
|
||||
"""
|
||||
pass
|
||||
|
||||
def is_for_infer(self) -> bool:
|
||||
"""
|
||||
@@ -201,7 +199,7 @@ class MinMaxNorm(Processor):
|
||||
self.fit_end_time = fit_end_time
|
||||
self.fields_group = fields_group
|
||||
|
||||
def fit(self, df):
|
||||
def fit(self, df: pd.DataFrame = None):
|
||||
df = fetch_df_by_index(df, slice(self.fit_start_time, self.fit_end_time), level="datetime")
|
||||
cols = get_group_columns(df, self.fields_group)
|
||||
self.min_val = np.nanmin(df[cols].values, axis=0)
|
||||
@@ -232,7 +230,7 @@ class ZScoreNorm(Processor):
|
||||
self.fit_end_time = fit_end_time
|
||||
self.fields_group = fields_group
|
||||
|
||||
def fit(self, df):
|
||||
def fit(self, df: pd.DataFrame = None):
|
||||
df = fetch_df_by_index(df, slice(self.fit_start_time, self.fit_end_time), level="datetime")
|
||||
cols = get_group_columns(df, self.fields_group)
|
||||
self.mean_train = np.nanmean(df[cols].values, axis=0)
|
||||
@@ -272,7 +270,7 @@ class RobustZScoreNorm(Processor):
|
||||
self.fields_group = fields_group
|
||||
self.clip_outlier = clip_outlier
|
||||
|
||||
def fit(self, df):
|
||||
def fit(self, df: pd.DataFrame = None):
|
||||
df = fetch_df_by_index(df, slice(self.fit_start_time, self.fit_end_time), level="datetime")
|
||||
self.cols = get_group_columns(df, self.fields_group)
|
||||
X = df[self.cols].values
|
||||
@@ -351,6 +349,6 @@ class HashStockFormat(Processor):
|
||||
"""Process the storage of from df into hasing stock format"""
|
||||
|
||||
def __call__(self, df: pd.DataFrame):
|
||||
from .storage import HasingStockStorage
|
||||
from .storage import HasingStockStorage # pylint: disable=C0415
|
||||
|
||||
return HasingStockStorage.from_df(df)
|
||||
|
||||
@@ -2,7 +2,7 @@ import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
from .handler import DataHandler
|
||||
from typing import Tuple, Union, List, Callable
|
||||
from typing import Union, List, Callable
|
||||
|
||||
from .utils import get_level_index, fetch_df_by_index, fetch_df_by_col
|
||||
|
||||
@@ -109,7 +109,7 @@ class HasingStockStorage(BaseHandlerStorage):
|
||||
stock_selector = selector[self.stock_level]
|
||||
elif isinstance(selector, (list, str)) and self.stock_level == 0:
|
||||
stock_selector = selector
|
||||
elif level == "instrument" or level == self.stock_level:
|
||||
elif level in ("instrument", self.stock_level):
|
||||
if isinstance(selector, tuple):
|
||||
stock_selector = selector[0]
|
||||
elif isinstance(selector, (list, str)):
|
||||
|
||||
@@ -63,7 +63,7 @@ def fetch_df_by_index(
|
||||
Data of the given index.
|
||||
"""
|
||||
# level = None -> use selector directly
|
||||
if level == None:
|
||||
if level is None:
|
||||
return df.loc(axis=0)[selector]
|
||||
# Try to get the right index
|
||||
idx_slc = (selector, slice(None, None))
|
||||
@@ -75,7 +75,7 @@ def fetch_df_by_index(
|
||||
return df.loc[
|
||||
pd.IndexSlice[idx_slc],
|
||||
]
|
||||
else:
|
||||
else: # pylint: disable=W0120
|
||||
return df
|
||||
else:
|
||||
return df.loc[
|
||||
@@ -84,7 +84,7 @@ def fetch_df_by_index(
|
||||
|
||||
|
||||
def fetch_df_by_col(df: pd.DataFrame, col_set: Union[str, List[str]]) -> pd.DataFrame:
|
||||
from .handler import DataHandler
|
||||
from .handler import DataHandler # pylint: disable=C0415
|
||||
|
||||
if not isinstance(df.columns, pd.MultiIndex) or col_set == DataHandler.CS_RAW:
|
||||
return df
|
||||
@@ -136,7 +136,7 @@ def init_task_handler(task: dict) -> Union[DataHandler, None]:
|
||||
returns
|
||||
"""
|
||||
# avoid recursive import
|
||||
from .handler import DataHandler
|
||||
from .handler import DataHandler # pylint: disable=C0415
|
||||
|
||||
h_conf = task["dataset"]["kwargs"].get("handler")
|
||||
if h_conf is not None:
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from typing import Union, List, Tuple
|
||||
from ...data.dataset import TSDataSampler
|
||||
from ...data.dataset.utils import get_level_index
|
||||
from ...utils import lazy_sort_index
|
||||
|
||||
|
||||
class Reweighter:
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user