Skip to content

Commit d1af9fd

Browse files
committed
EditDomain: Skip attributes when describing old vars
Widget uses a dict for mapping of old variable descriptions to the new ones. If an old variable contains values in its attributes dict, which are not hashable, this makes description not hashable as well. This is worked around by matching old variables by everything except attributes. Fixes #1527
1 parent d3c50bd commit d1af9fd

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Orange/widgets/data/oweditdomain.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def get_qualified(module, name):
3737
return getattr(module, name)
3838

3939

40-
def variable_description(var):
40+
def variable_description(var, skip_attributes=False):
4141
"""Return a variable descriptor.
4242
4343
A descriptor is a hashable tuple which should uniquely define
@@ -46,18 +46,21 @@ def variable_description(var):
4646
4747
"""
4848
var_type = type(var)
49+
attributes = ()
50+
if not skip_attributes:
51+
attributes = tuple(sorted(var.attributes.items()))
4952
if var.is_discrete:
5053
return (var_type.__module__,
5154
var_type.__name__,
5255
var.name,
5356
(("values", tuple(var.values)),),
54-
tuple(sorted(var.attributes.items())))
57+
attributes)
5558
else:
5659
return (var_type.__module__,
5760
var_type.__name__,
5861
var.name,
5962
(),
60-
tuple(sorted(var.attributes.items())))
63+
attributes)
6164

6265

6366
def variable_from_description(description, compute_value=None):
@@ -423,7 +426,7 @@ def reset_selected(self):
423426
ind = self.selected_var_index()
424427
if ind >= 0:
425428
var = self.input_vars[ind]
426-
desc = variable_description(var)
429+
desc = variable_description(var, skip_attributes=True)
427430
if desc in self.domain_change_hints:
428431
del self.domain_change_hints[desc]
429432

@@ -454,7 +457,7 @@ def _initialize(self):
454457
def _restore(self):
455458
# Restore the variable states from saved settings.
456459
def transform(var):
457-
vdesc = variable_description(var)
460+
vdesc = variable_description(var, skip_attributes=True)
458461
if vdesc in self.domain_change_hints:
459462
return variable_from_description(
460463
self.domain_change_hints[vdesc],
@@ -513,8 +516,8 @@ def _on_variable_changed(self):
513516

514517

515518
# Store the transformation hint.
516-
self.domain_change_hints[variable_description(old_var)] = \
517-
variable_description(new_var)
519+
old_var_desc = variable_description(old_var, skip_attributes=True)
520+
self.domain_change_hints[old_var_desc] = variable_description(new_var)
518521

519522
self._invalidate()
520523

0 commit comments

Comments
 (0)