Skip to content

Commit

Permalink
Merge pull request #3707 from janezd/pylint-owfile2
Browse files Browse the repository at this point in the history
Data widgets: PyLint
  • Loading branch information
janezd authored Apr 1, 2019
2 parents aaea036 + 91e6899 commit 2207e2d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
5 changes: 3 additions & 2 deletions Orange/widgets/data/owfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ def add_origin(examples, filename):
"""
if not filename:
return
vars = examples.domain.variables + examples.domain.metas
strings = [var for var in vars if var.is_string]
strings = [var
for var in examples.domain.variables + examples.domain.metas
if var.is_string]
dir_name, _ = os.path.split(filename)
for var in strings:
if "type" in var.attributes and "origin" not in var.attributes:
Expand Down
3 changes: 1 addition & 2 deletions Orange/widgets/data/owmergedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ def dataInfoText(data):

def commit(self):
self.Warning.duplicate_names.clear()
if self.data is None or len(self.data) == 0 or \
self.extra_data is None or len(self.extra_data) == 0:
if not self.data or not self.extra_data:
merged_data = None
else:
merged_data = self.merge()
Expand Down
5 changes: 2 additions & 3 deletions Orange/widgets/data/owneighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _set_label_text(self, name):
if data is None:
label.setText(f"No {name} instances")
else:
pl = "s" if len(data) else ""
pl = "s" if data else ""
label.setText(f"{len(data)} {name} instance{pl} on input.")

@Inputs.data
Expand All @@ -114,8 +114,7 @@ def recompute(self):

def compute_distances(self):
self.Error.diff_domains.clear()
if self.data is None or len(self.data) == 0 \
or self.reference is None or len(self.reference) == 0:
if not self.data or not self.reference:
self.distances = None
return
if set(self.reference.domain.attributes) != \
Expand Down
10 changes: 5 additions & 5 deletions Orange/widgets/data/owpaintdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def __init__(self):
self.class_model.rowsInserted.connect(self._class_count_changed)
self.class_model.rowsRemoved.connect(self._class_count_changed)

if self.data is None or not len(self.data):
if not self.data:
self.data = []
self.__buffer = np.zeros((0, 3))
elif isinstance(self.data, np.ndarray):
Expand Down Expand Up @@ -998,15 +998,15 @@ def _check_and_set_data(data):
if data and data.is_sparse():
self.Warning.sparse_not_supported()
return False
if data is not None and len(data):
if data:
if not data.domain.attributes:
self.Warning.no_input_variables()
data = None
elif len(data.domain.attributes) > 2:
self.Information.use_first_two()
self.input_data = data
self.btResetToInput.setDisabled(data is None)
return data is not None and len(data)
return bool(data)

if not _check_and_set_data(data):
return
Expand Down Expand Up @@ -1264,10 +1264,10 @@ def invalidate(self):
self.commit()

def commit(self):
data = np.array(self.data)
if len(data) == 0:
if not self.data:
self.Outputs.data.send(None)
return
data = np.array(self.data)
if self.hasAttr2:
X, Y = data[:, :2], data[:, 2]
attrs = (Orange.data.ContinuousVariable(self.attr1),
Expand Down
1 change: 1 addition & 0 deletions Orange/widgets/data/owsave.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ class SaveFileDialog(QFileDialog):
# pylint: disable=protected-access
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.suffix = ""
self.setAcceptMode(QFileDialog.AcceptSave)
self.setOption(QFileDialog.DontUseNativeDialog)
self.filterSelected.connect(self.updateDefaultExtension)
Expand Down
12 changes: 7 additions & 5 deletions Orange/widgets/data/owselectbydataindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def set_data_subset(self, data):
def handleNewSignals(self):
self._invalidate()

def data_info_text(self, data):
@staticmethod
def data_info_text(data):
if data is None:
return "No data."
else:
Expand All @@ -81,7 +82,8 @@ def commit(self):
non_matching_output = None
annotated_output = None
else:
if self.data_subset and len(np.intersect1d(subset_ids, self.data.ids)) == 0:
if self.data_subset and \
not np.intersect1d(subset_ids, self.data.ids).size:
self.Warning.instances_not_matching()
row_sel = np.in1d(self.data.ids, subset_ids)
matching_output = self.data[row_sel]
Expand All @@ -101,7 +103,7 @@ def send_report(self):


if __name__ == "__main__": # pragma: no cover
data = Table("iris.tab")
iris = Table("iris.tab")
WidgetPreview(OWSelectByDataIndex).run(
set_data=data,
set_data_subset=data[:20])
set_data=iris,
set_data_subset=iris[:20])
1 change: 1 addition & 0 deletions Orange/widgets/data/owtranspose.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(self):
super().__init__()
self.data = None

# self.apply is changed later, pylint: disable=unnecessary-lambda
box = gui.radioButtons(
self.controlArea, self, "feature_type", box="Feature names",
callback=lambda: self.apply())
Expand Down

0 comments on commit 2207e2d

Please sign in to comment.