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.

Issues (4082)

Orange/misc/distmatrix.py (9 issues)

1
import numpy as np
0 ignored issues
show
The import numpy could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
2
from Orange.util import deprecated
3
4
5
class DistMatrix(np.ndarray):
6
    """
7
    Distance matrix. Extends ``numpy.ndarray``.
8
9
    .. attribute:: row_items
10
11
        Items corresponding to matrix rows.
12
13
    .. attribute:: col_items
14
15
        Items corresponding to matrix columns.
16
17
    .. attribute:: axis
18
19
        If axis=1 we calculate distances between rows,
20
        if axis=0 we calculate distances between columns.
21
    """
22
    def __new__(cls, data, row_items=None, col_items=None, axis=1):
23
        """Construct a new distance matrix containing the given data.
24
25
        :param data: Distance matrix
26
        :type data: numpy array
27
        :param row_items: Items in matrix rows
28
        :type row_items: `Orange.data.Table` or `Orange.data.Instance`
29
        :param col_items: Items in matrix columns
30
        :type col_items: `Orange.data.Table` or `Orange.data.Instance`
31
        :param axis: The axis along which the distances are calculated
32
        :type axis: int
33
34
        """
35
        obj = np.asarray(data).view(cls)
36
        obj.row_items = row_items
37
        obj.col_items = col_items
38
        obj.axis = axis
39
        return obj
40
41
    def __array_finalize__(self, obj):
42
        """See http://docs.scipy.org/doc/numpy/user/basics.subclassing.html"""
43
        if obj is None: return
44
        self.row_items = getattr(obj, 'row_items', None)
0 ignored issues
show
The attribute row_items was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
45
        self.col_items = getattr(obj, 'col_items', None)
0 ignored issues
show
The attribute col_items was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
46
        self.axis = getattr(obj, 'axis', 1)
0 ignored issues
show
The attribute axis was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
47
48
    def __array_wrap__(self, out_arr, context=None):
49
        if out_arr.ndim == 0:  # a single scalar
50
            return out_arr.item()
51
        return np.ndarray.__array_wrap__(self, out_arr, context)
52
53
    """
54
    __reduce__() and __setstate__() ensure DistMatrix is picklable.
55
    """
0 ignored issues
show
This string statement has no effect and could be removed.
Loading history...
56
    def __reduce__(self):
57
        state = super().__reduce__()
58
        newstate = state[2] + (self.row_items, self.col_items, self.axis)
59
        return state[0], state[1], newstate
60
61
    def __setstate__(self, state):
62
        self.row_items = state[-3]
0 ignored issues
show
The attribute row_items was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
63
        self.col_items = state[-2]
0 ignored issues
show
The attribute col_items was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
64
        self.axis = state[-1]
0 ignored issues
show
The attribute axis was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
65
        super().__setstate__(state[0:-3])
66
67
    @property
68
    @deprecated
69
    def dim(self):
70
        """Returns the single dimension of the symmetric square matrix."""
71
        return self.shape[0]
72
73
    @property
74
    @deprecated
75
    def X(self):
76
        return self
77
78
    @property
79
    def flat(self):
80
        return self[np.triu_indices(self.shape[0], 1)]
81
82
    def get_KNN(self, i, k):
0 ignored issues
show
The argument k seems to be unused.
Loading history...
83
        """Return k columns with the lowest value in the i-th row.
84
85
        :param i: i-th row
86
        :type i: int
87
        :param k: number of neighbors
88
        :type k: int
89
        """
90
        idxs = np.argsort(self[i, :])[:]
91
        return self[:, idxs]
92
93
    def invert(self, typ):
94
        """Invert values in the distance matrix.
95
96
        :param type: 0 (-X), 1 (1 - X), 2 (max - X), 3 (1 / X)
97
        :type type: int
98
        """
99
        if typ == 0:
100
            return -self
101
        elif typ == 1:
102
            return 1.-self
103
        elif typ == 2:
104
            return 1./self
105
        else:
106
            raise ValueError('Unknown option for typ of matrix inversion.')
107
108
    def submatrix(self, row_items, col_items=None):
109
        """Return a submatrix of self, describing only distances between items"""
110
        if not col_items:
111
            col_items = row_items
112
        obj = self[np.ix_(row_items, col_items)]
113
        if obj.row_items:
114
            obj.row_items = self.row_items[row_items]
115
        if obj.col_items:
116
            obj.col_items = self.col_items[col_items]
117
        return obj
118