Passed
Push — dev ( 1b3874...6a1e3c )
by Konstantinos
03:33
created

green_magic.data.variables.features_set   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 13
eloc 32
dl 0
loc 44
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A BaseFeatureSet.__len__() 0 2 1
A FeatureSet.not_encoded() 0 5 3
A BaseFeatureSet.__iter__() 0 2 1
A BaseFeatureSet.from_raw_extractors() 0 4 1
A FeatureSet.binnable() 0 5 3
A FeatureSet.encoded() 0 5 3
A BaseFeatureSet.__getitem__() 0 2 1
1
import attr
2
3
from .types import NominalVariableType
4
from .features import TrackingFeature
5
6
@attr.s
7
class BaseFeatureSet:
8
    features = attr.ib(init=True, default=[])
9
10
    def __len__(self):
11
        return len(self.features)
12
13
    def __getitem__(self, item):
14
        return self.features[item]
15
16
    def __iter__(self):
17
        return iter(self.features)
18
19
    @classmethod
20
    def from_raw_extractors(cls, data):
21
        """Create a Feature for each of the lists in the input data (list). Inner lists must satisfy 0 < len(l)"""
22
        return [TrackingFeature.from_callable(*args) for args in data]
23
24
25
class FeatureSet(BaseFeatureSet):
26
27
    @property
28
    def encoded(self):
29
        for feature in self.features:
30
            if str(feature.state) == 'encoded':
31
                yield feature
32
33
    @property
34
    def not_encoded(self):
35
        for feature in self.features:
36
            if str(feature.state) != 'encoded':
37
                yield feature
38
39
    @property
40
    def binnable(self):
41
        for feature in self.features:
42
            if not isinstance(feature.var_type, NominalVariableType):
43
                yield feature
44