GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 9dda1d...5890d9 )
by Hugo
08:00 queued 03:26
created

Orange.statistics._get_variable()   B

Complexity

Conditions 6

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 6
dl 0
loc 13
rs 8
1
from Orange.data import Variable, Storage
2
3
def _get_variable(variable, dat):
4
    if isinstance(variable, Variable):
5
        datvar = getattr(dat, "variable", None)
6
        if datvar is not None and datvar is not variable:
7
            raise ValueError("variable does not match the variable "
8
                             "in the data")
9
    elif hasattr(dat, "domain"):
10
        variable = dat.domain[variable]
11
    elif hasattr(dat, "variable"):
12
        variable = dat.variable
13
    else:
14
        raise ValueError("invalid specification of variable")
15
    return variable
16
17
18
class BasicStats:
19
    def __init__(self, dat=None, variable=None):
20
        if isinstance(dat, Storage):
21
            self.from_data(dat, variable)
22
        elif dat is None:
23
            self.min = float("inf")
24
            self.max = float("-inf")
25
            self.mean = self.var = self.nans = self.non_nans = 0
26
        else:
27
            self.min, self.max, self.mean, self.var, self.nans, self.non_nans \
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are trying to unpack a non-sequence, which was defined at line 19.
Loading history...
28
                = dat
29
30
    def from_data(self, data, variable):
31
        variable = _get_variable(variable, data)
32
        stats = data._compute_basic_stats([variable])
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _compute_basic_stats was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
33
        self.min, self.max, self.mean, self.var, self.nans, self.non_nans \
34
            = stats[0]
35
36
class DomainBasicStats:
37
    def __init__(self, data, include_metas=False):
38
        self.domain = data.domain
39
        self.stats = [BasicStats(s) for s in
40
                      data._compute_basic_stats(include_metas=include_metas)]
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _compute_basic_stats was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
41
42
    def __getitem__(self, index):
43
        """
44
        Index can be a variable, variable name or an integer. Meta attributes
45
        can be specified by negative indices or by indices above len(domain).
46
        """
47
        if not isinstance(index, int):
48
            index = self.domain.index(index)
49
        if index < 0:
50
            index = len(self.domain) + (-1 - index)
51
        return self.stats[index]
52
53