Passed
Push — main ( 081b85...deff66 )
by Mohammad
02:40 queued 12s
created

tracking_policy_agendas.classifiers.meta_sklearn_clf   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 27
Duplicated Lines 77.78 %

Test Coverage

Coverage 68.18%

Importance

Changes 0
Metric Value
wmc 10
eloc 23
dl 21
loc 27
ccs 15
cts 22
cp 0.6818
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A MetaSkLearnClf.__init__() 3 3 2
A MetaSkLearnClf.load_model() 7 7 4
A MetaSkLearnClf.save_model() 8 8 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1 1
import os
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2 1
import pickle
3 1
from .meta_clf import MetaClf
4
5
6 1 View Code Duplication
class MetaSkLearnClf(MetaClf):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
7 1
    def __init__(self, classifier_instance, **kwargs):
8 1
        super().__init__(classifier_instance=classifier_instance, **kwargs)
9 1
        if kwargs['load_path'] is not None: self.load_model(kwargs['load_path'])
0 ignored issues
show
Coding Style introduced by
More than one statement on a single line
Loading history...
10
11 1
    def load_model(self, load_path: str):
12 1
        loading_prep = lambda string: f'model_dir/{load_path}/{string}'
13 1
        self.emb.load(loading_prep('emb.pkl'))
14 1
        with open(loading_prep('model.pkl'), 'rb') as f:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
15 1
            self.clf = pickle.load(f)
16 1
        with open(loading_prep('scaler.pkl'), 'rb') as f:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
17 1
            self.scaler = pickle.load(f)
18
19 1
    def save_model(self, save_path: str):
20
        os.makedirs(f'model_dir/{save_path}', exist_ok=True)
21
        saving_prep = lambda string: f'model_dir/{save_path}/{string}'
22
        self.emb.save(saving_prep('emb.pkl'))
23
        with open(saving_prep('scaler.pkl'), 'wb') as f:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
24
            pickle.dump(self.scaler, f, pickle.HIGHEST_PROTOCOL)
25
        with open(saving_prep('model.pkl'), 'wb') as f:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
26
            pickle.dump(self.clf, f, pickle.HIGHEST_PROTOCOL)
27