Skip to content

Commit

Permalink
domaineditor: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Feb 27, 2020
1 parent a78c8f4 commit 150fdb1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
16 changes: 11 additions & 5 deletions Orange/widgets/utils/domaineditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ def set_variables(self, variables):
def rowCount(self, parent):
return 0 if parent.isValid() else len(self.variables)

def columnCount(self, parent):
@staticmethod
def columnCount(parent):
return 0 if parent.isValid() else Column.not_valid

def data(self, index, role):
row, col = index.row(), index.column()
val = self.variables[row][col]
if role == Qt.DisplayRole or role == Qt.EditRole:
if role in (Qt.DisplayRole, Qt.EditRole):
if col == Column.tpe:
return self.type2name[val]
if col == Column.place:
Expand All @@ -91,6 +92,7 @@ def data(self, index, role):
font = QFont()
font.setBold(True)
return font
return None

def setData(self, index, value, role=Qt.EditRole):
row, col = index.row(), index.column()
Expand All @@ -111,6 +113,7 @@ def setData(self, index, value, role=Qt.EditRole):
# Settings may change background colors
self.dataChanged.emit(index.sibling(row, 0), index.sibling(row, 3))
return True
return False

def headerData(self, i, orientation, role=Qt.DisplayRole):
if orientation == Qt.Horizontal and role == Qt.DisplayRole and i < 4:
Expand All @@ -131,7 +134,7 @@ def __init__(self, view, items):
self.view = view
self.items = items

def createEditor(self, parent, option, index):
def createEditor(self, parent, _option, index):
# This ugly hack closes the combo when the user selects an item
class Combo(QComboBox):
def __init__(self, *args):
Expand All @@ -146,6 +149,8 @@ def showPopup(self, *args):
super().showPopup(*args)
self.popup_shown = True

# Here, we need `self` from the closure
# pylint: disable=no-self-argument,attribute-defined-outside-init
def hidePopup(me):
if me.popup_shown:
self.view.model().setData(
Expand Down Expand Up @@ -356,7 +361,7 @@ def numbers_are_round(var, col_data):

# merge columns for X, Y and metas
feats = cols[Place.feature]
X = self._merge(feats) if len(feats) else np.empty((len(data), 0))
X = self._merge(feats) if feats else np.empty((len(data), 0))
Y = self._merge(cols[Place.class_var], force_dense=True)
m = self._merge(cols[Place.meta], force_dense=True)
domain = Domain(*places)
Expand All @@ -365,7 +370,8 @@ def numbers_are_round(var, col_data):
else:
return domain, [X, Y, m]

def _get_column(self, data, source_var, source_place):
@staticmethod
def _get_column(data, source_var, source_place):
""" Extract column from data and preserve sparsity. """
if source_place == Place.meta:
col_data = data[:, source_var].metas
Expand Down
3 changes: 1 addition & 2 deletions Orange/widgets/utils/tests/test_domaineditor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import unittest
from unittest.mock import Mock

import numpy as np

Expand All @@ -8,7 +7,7 @@
from Orange.data import DiscreteVariable, ContinuousVariable, StringVariable, \
TimeVariable, Domain, Table
from Orange.widgets.tests.base import GuiTest
from Orange.widgets.utils.domaineditor import DomainEditor, Column, Place
from Orange.widgets.utils.domaineditor import DomainEditor, Column


class MockWidget(OWBaseWidget):
Expand Down

0 comments on commit 150fdb1

Please sign in to comment.