Skip to content

Commit 2338a2a

Browse files
committed
OWMergeData: Fix report, other minor fixes
1 parent 3de38b3 commit 2338a2a

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

Orange/widgets/data/owmergedata.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ class Outputs:
157157
replaces=["Merged Data A+B", "Merged Data B+A", "Merged Data"])
158158

159159
LeftJoin, InnerJoin, OuterJoin = range(3)
160+
OptionNames = ("Append columns from Extra data",
161+
"Find matching pairs of rows",
162+
"Concatenate tables")
160163

161164
attr_pairs = Setting('', schema_only=True)
162165
merging = Setting(LeftJoin)
@@ -171,9 +174,9 @@ class Warning(widget.OWWidget.Warning):
171174

172175
class Error(widget.OWWidget.Error):
173176
matching_numeric_with_nonnum = Msg(
174-
"Numeric and non-numeric columns ('{}' and '{}') can't be matched.")
175-
matching_index_with_sth = Msg("Row index cannot by matched with '{}'.")
176-
matching_id_with_sth = Msg("Instance if cannot by matched with '{}'.")
177+
"Numeric and non-numeric columns ({} and {}) can't be matched.")
178+
matching_index_with_sth = Msg("Row index cannot by matched with {}.")
179+
matching_id_with_sth = Msg("Instance cannot by matched with {}.")
177180
nonunique_left = Msg(
178181
"Some combinations of values on the left appear in multiple rows.\n"
179182
"For this type of merging, every possible combination of values "
@@ -204,10 +207,7 @@ def __init__(self):
204207

205208
grp = gui.radioButtons(
206209
self.controlArea, self, "merging", box="Merging",
207-
btnLabels=("Append columns from Extra data",
208-
"Find matching pairs of rows",
209-
"Concatenate tables"),
210-
callback=self.change_merging)
210+
btnLabels=self.OptionNames, callback=self.change_merging)
211211
grp.layout().setSpacing(8)
212212

213213
self.attr_boxes = box = ConditionBox(
@@ -216,9 +216,9 @@ def __init__(self):
216216
radio_width = \
217217
QApplication.style().pixelMetric(QStyle.PM_ExclusiveIndicatorWidth)
218218
gui.indentedBox(grp, radio_width).layout().addWidget(box)
219-
box.vars_changed.connect(lambda: self.commit)
220219
gui.auto_commit(self.controlArea, self, "auto_apply", "&Apply",
221220
box=False)
221+
box.vars_changed.connect(self.commit) # connect after auto_commit!
222222
self.settingsAboutToBePacked.connect(self.store_combo_state)
223223

224224
def store_combo_state(self):
@@ -324,16 +324,12 @@ def commit(self):
324324

325325
def send_report(self):
326326
# pylint: disable=invalid-sequence-index
327-
attr = (self.attr_augment_data, self.attr_merge_data,
328-
self.attr_combine_data)
329-
extra_attr = (self.attr_augment_extra, self.attr_merge_extra,
330-
self.attr_combine_extra)
331-
merging_types = ("Append columns from Extra Data", "Find matching rows",
332-
"Concatenate tables, merge rows")
333327
self.report_items((
334-
("Merging", merging_types[self.merging]),
335-
("Data attribute", attr[self.merging]),
336-
("Extra data attribute", extra_attr[self.merging])))
328+
("Merging", self.OptionNames[self.merging]),
329+
("Match",
330+
", ".join(
331+
f"{self._get_col_name(left)} with {self._get_col_name(right)}"
332+
for left, right in self.attr_boxes.current_state()))))
337333

338334
def merge(self):
339335
# pylint: disable=invalid-sequence-index
@@ -355,28 +351,29 @@ def merge(self):
355351
return self._join_table_by_indices(reduced_extra_data, lefti, righti)
356352

357353
def _check_pair_types(self, pairs):
358-
def get_name(obj):
359-
return obj.name if isinstance(obj, Variable) else obj
360-
361354
for left, right in pairs:
362355
if isinstance(left, ContinuousVariable) \
363356
!= isinstance(right, ContinuousVariable):
364357
self.Error.matching_numeric_with_nonnum(left, right)
365358
return False
366359
if INDEX in (left, right) and left != right:
367360
self.Error.matching_index_with_sth(
368-
get_name({left, right} - {INDEX}).pop())
361+
self._get_col_name(({left, right} - {INDEX}).pop()))
369362
return False
370363
if INSTANCEID in (left, right) and left != right:
371364
self.Error.matching_id_with_sth(
372-
get_name({left, right} - {INSTANCEID}).pop())
365+
self._get_col_name(({left, right} - {INSTANCEID}).pop()))
373366
return False
374367
if (isinstance(left, str) or isinstance(right, str)) \
375368
and left != right:
376369
self.Error.matching_position_with_sth_else()
377370
return False
378371
return True
379372

373+
@staticmethod
374+
def _get_col_name(obj):
375+
return f"'{obj.name}'" if isinstance(obj, Variable) else obj.lower()
376+
380377
def _check_uniqueness(self, left, left_mask, right, right_mask):
381378
ok = True
382379
masked_right = right[right_mask]

Orange/widgets/data/tests/test_owmergedata.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Test methods with long descriptive names can omit docstrings
22
# pylint: disable=missing-docstring
33
from itertools import chain
4-
from unittest.mock import patch
54

65
import numpy as np
76
import scipy.sparse as sp

0 commit comments

Comments
 (0)