Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed code quality issues #311

Merged
merged 11 commits into from Mar 12, 2021
12 changes: 12 additions & 0 deletions .deepsource.toml
@@ -0,0 +1,12 @@
version = 1

test_patterns = ["tests/test_*.py"]

exclude_patterns = ["examples/**"]

[[analyzers]]
name = "python"
enabled = true

[analyzers.meta]
runtime_version = "3.x.x"
4 changes: 2 additions & 2 deletions qlib/contrib/evaluate_portfolio.py
Expand Up @@ -61,7 +61,7 @@ def get_position_value(evaluate_date, position):
# load close price for position
# position should also consider cash
instruments = list(position.keys())
instruments = list(set(instruments) - set(["cash"])) # filter 'cash'
instruments = list(set(instruments) - {"cash"}) # filter 'cash'
fields = ["$close"]
close_data_df = D.features(
instruments,
Expand All @@ -80,7 +80,7 @@ def get_position_list_value(positions):
instruments = set()
for day, position in positions.items():
instruments.update(position.keys())
instruments = list(set(instruments) - set(["cash"])) # filter 'cash'
instruments = list(set(instruments) - {"cash"}) # filter 'cash'
instruments.sort()
day_list = list(positions.keys())
day_list.sort()
Expand Down
2 changes: 1 addition & 1 deletion qlib/contrib/online/manager.py
Expand Up @@ -63,7 +63,7 @@ def load_user(self, user_id):
account_path = self.data_path / user_id
strategy_file = self.data_path / user_id / "strategy_{}.pickle".format(user_id)
model_file = self.data_path / user_id / "model_{}.pickle".format(user_id)
cur_user_list = [user_id for user_id in self.users]
cur_user_list = list(self.users)
if user_id in cur_user_list:
raise ValueError("User {} has been loaded".format(user_id))
else:
Expand Down
2 changes: 1 addition & 1 deletion qlib/contrib/report/graph.py
Expand Up @@ -161,7 +161,7 @@ def _get_data(self):
"""
_t_df = self._df.dropna()
_data_list = [_t_df[_col] for _col in self._name_dict]
_label_list = [_name for _name in self._name_dict.values()]
_label_list = list(self._name_dict.values())
_fig = create_distplot(_data_list, _label_list, show_rug=False, **self._graph_kwargs)

return _fig["data"]
Expand Down
3 changes: 0 additions & 3 deletions qlib/data/cache.py
Expand Up @@ -1045,9 +1045,6 @@ def _dataset(self, instruments, fields, start_time=None, end_time=None, freq="da
class DatasetURICache(DatasetCache):
"""Prepared cache mechanism for server."""

def __init__(self, provider):
super(DatasetURICache, self).__init__(provider)

def _uri(self, instruments, fields, start_time, end_time, freq, disk_cache=1, **kwargs):
return hash_args(*self.normalize_uri_args(instruments, fields, freq), disk_cache)

Expand Down
3 changes: 0 additions & 3 deletions qlib/data/data.py
Expand Up @@ -654,9 +654,6 @@ class LocalExpressionProvider(ExpressionProvider):
Provide expression data from local data source.
"""

def __init__(self):
super().__init__()

def expression(self, instrument, field, start_time=None, end_time=None, freq="day"):
expression = self.get_expression_instance(field)
start_time = pd.Timestamp(start_time)
Expand Down
13 changes: 1 addition & 12 deletions qlib/data/dataset/__init__.py
Expand Up @@ -76,18 +76,7 @@ class DatasetH(Dataset):
- The processing is related to data split.
"""

def __init__(self, handler: Union[Dict, DataHandler], segments: Dict):
"""
Parameters
----------
handler : Union[dict, DataHandler]
handler will be passed into setup_data.
segments : dict
handler will be passed into setup_data.
"""
super().__init__(handler, segments)

def init(self, handler_kwargs: Optional[Dict] = None, segment_kwargs: Optional[Dict] = None):
def init(self, handler_kwargs: dict = None, segment_kwargs: dict = None):
"""
Initialize the DatasetH

Expand Down
2 changes: 1 addition & 1 deletion qlib/utils/__init__.py
Expand Up @@ -212,7 +212,7 @@ def get_cls_kwargs(config: Union[dict, str], module) -> (type, dict):


def init_instance_by_config(
config: Union[str, dict, object], module=None, accept_types: Union[type, Tuple[type]] = tuple([]), **kwargs
config: Union[str, dict, object], module=None, accept_types: Union[type, Tuple[type]] = (), **kwargs
) -> object:
"""
get initialized instance with config
Expand Down