Skip to content

Commit dbf5ac4

Browse files
committed
OWMergData: Fix reloading schema settings
1 parent c9e5a76 commit dbf5ac4

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

Orange/widgets/data/owmergedata.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from collections import namedtuple
22
from itertools import chain, product
33

4+
import numpy as np
5+
46
from AnyQt.QtCore import pyqtSignal as Signal
57
from AnyQt.QtWidgets import QApplication, QStyle, QWidget, \
68
QLabel, QComboBox, QPushButton, QVBoxLayout, QHBoxLayout
79

8-
import numpy as np
9-
1010
import Orange
1111
from Orange.data import StringVariable, ContinuousVariable, Variable
1212
from Orange.data.util import hstack
@@ -160,7 +160,7 @@ class Outputs:
160160
"Find matching pairs of rows",
161161
"Concatenate tables")
162162

163-
attr_pairs = Setting('', schema_only=True)
163+
attr_pairs = Setting(None, schema_only=True)
164164
merging = Setting(LeftJoin)
165165
auto_apply = Setting(True)
166166
settings_version = 1
@@ -220,9 +220,6 @@ def __init__(self):
220220
box.vars_changed.connect(self.commit) # connect after auto_commit!
221221
self.settingsAboutToBePacked.connect(self.store_combo_state)
222222

223-
def store_combo_state(self):
224-
self.attr_pairs = self.attr_boxes.current_state()
225-
226223
def change_merging(self):
227224
self.commit()
228225

@@ -280,13 +277,33 @@ def _restore_combo_current_items(self, side, prev_settings):
280277
self._try_set_combo(
281278
[row.left_combo, row.right_combo][side], pair[side])
282279

280+
def store_combo_state(self):
281+
self.attr_pairs = (
282+
self.data is not None,
283+
self.extra_data is not None,
284+
[[[INDEX, INSTANCEID].index(x) if isinstance(x, str) else x.name
285+
for x in row]
286+
for row in self.attr_boxes.current_state()])
287+
283288
def handleNewSignals(self):
284-
if self.attr_pairs and self.data:
285-
# TODO: This doesn't work, but should after #3925 (remove make)
286-
self.attr_boxes.set_state(self.attr_pairs)
289+
if self.attr_pairs \
290+
and self.attr_pairs[:2] == (self.data is not None,
291+
self.extra_data is not None):
292+
def unpack(x, data):
293+
if isinstance(x, int):
294+
return [INDEX, INSTANCEID][x]
295+
if data is not None and x in data.domain:
296+
return data.domain[x]
297+
else:
298+
return INDEX
299+
300+
state = [
301+
[unpack(row[0], self.data), unpack(row[1], self.extra_data)]
302+
for row in self.attr_pairs[2]]
303+
self.attr_boxes.set_state(state)
287304
# This is schema-only setting, so it should be single-shot
288305
# More complicated alternative: make it a context setting
289-
self.attr_pairs = []
306+
self.attr_pairs = None
290307
self._find_best_match()
291308
box = self.attr_boxes
292309

@@ -516,8 +533,10 @@ def migrate_settings(settings, version=None):
516533
if not version:
517534
operations = ("augment", "merge", "combine")
518535
oper = [settings["merging"]]
519-
settings["attr_pairs"] = [(settings[f"attr_{oper}_data"],
520-
settings[f"attr_{oper}_extra"])]
536+
settings["attr_pairs"] = (
537+
True, True,
538+
[(settings[f"attr_{oper}_data"],
539+
settings[f"attr_{oper}_extra"])])
521540
for oper in operations:
522541
del settings[f"attr_{oper}_data"]
523542
del settings[f"attr_{oper}_extra"]

0 commit comments

Comments
 (0)