Skip to content

Commit

Permalink
Fix pylint error
Browse files Browse the repository at this point in the history
  • Loading branch information
you-n-g committed Feb 15, 2022
1 parent 4e18356 commit 780202a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .pylintrc
@@ -0,0 +1,5 @@
[TYPECHECK]
# https://stackoverflow.com/a/53572939
# List of members which are set dynamically and missed by Pylint inference
# system, and so shouldn't trigger E1101 when accessed.
generated-members=numpy.*, torch.*
12 changes: 11 additions & 1 deletion docs/developer/code_standard.rst
Expand Up @@ -14,9 +14,19 @@ Continuous Integration (CI) tools help you stick to the quality standards by run

When you submit a PR request, you can check whether your code passes the CI tests in the "check" section at the bottom of the web page.

A common error is the mixed use of space and tab. You can fix the bug by inputing the following code in the command line.
1. Qlib will check the code format with black. The PR will raise error if your code does not align to the standard of Qlib(e.g. a common error is the mixed use of space and tab).
You can fix the bug by inputing the following code in the command line.

.. code-block:: python
pip install black
python -m black . -l 120
2. Qlib will check your code style pylint. The checking command is implemented in [github action workflow](https://github.com/microsoft/qlib/blob/0e8b94a552f1c457cfa6cd2c1bb3b87ebb3fb279/.github/workflows/test.yml#L66).
Sometime pylint's restrictions are not that reasonable. You can ignore specific errors like this

.. code-block:: python
return -ICLoss()(pred, target, index) # pylint: disable=E1130
4 changes: 2 additions & 2 deletions qlib/contrib/model/pytorch_gats.py
Expand Up @@ -263,8 +263,8 @@ def fit(

model_dict = self.GAT_model.state_dict()
pretrained_dict = {
k: v for k, v in pretrained_model.state_dict().items() if k in model_dict
} # pylint: disable=E1135
k: v for k, v in pretrained_model.state_dict().items() if k in model_dict # pylint: disable=E1135
}
model_dict.update(pretrained_dict)
self.GAT_model.load_state_dict(model_dict)
self.logger.info("Loading pretrained model Done...")
Expand Down
4 changes: 2 additions & 2 deletions qlib/contrib/model/pytorch_gats_ts.py
Expand Up @@ -278,8 +278,8 @@ def fit(

model_dict = self.GAT_model.state_dict()
pretrained_dict = {
k: v for k, v in pretrained_model.state_dict().items() if k in model_dict
} # pylint: disable=E1135
k: v for k, v in pretrained_model.state_dict().items() if k in model_dict # pylint: disable=E1135
}
model_dict.update(pretrained_dict)
self.GAT_model.load_state_dict(model_dict)
self.logger.info("Loading pretrained model Done...")
Expand Down
3 changes: 1 addition & 2 deletions qlib/contrib/model/pytorch_nn.py
Expand Up @@ -15,7 +15,6 @@
import torch
import torch.nn as nn
import torch.optim as optim
from qlib.model.utils import IndexSampler

from .pytorch_utils import count_parameters
from ...model.base import Model
Expand Down Expand Up @@ -344,7 +343,7 @@ def get_loss(self, pred, w, target, loss_type):

def get_metric(self, pred, target, index):
# NOTE: the order of the index must follow <datetime, instrument> sorted order
return -ICLoss()(pred, target, index)
return -ICLoss()(pred, target, index) # pylint: disable=E1130

def _nn_predict(self, data, return_cpu=True):
"""Reusing predicting NN.
Expand Down

0 comments on commit 780202a

Please sign in to comment.