Skip to content

Commit

Permalink
Merge pull request #4830 from PrimozGodec/fix-select-rows
Browse files Browse the repository at this point in the history
[FIX] Select Rows: Fix saving meta variables in context
  • Loading branch information
lanzagar authored May 28, 2020
2 parents f1ea981 + 91ad02f commit 804bc6a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Orange/widgets/data/owselectrows.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ def encode_setting(self, context, setting, value):
values = [QLocale().toDouble(v)[0] for v in values]
elif isinstance(attr, DiscreteVariable):
values = [attr.values[i - 1] if i else "" for i in values]
encoded.append(
(attr.name, context.attributes.get(attr.name), op, values))
encoded.append((
attr.name,
context.attributes.get(attr.name)
or context.metas.get(attr.name),
op,
values
))
return encoded

def decode_setting(self, setting, value, domain=None):
Expand Down
30 changes: 30 additions & 0 deletions Orange/widgets/data/tests/test_owselectrows.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,36 @@ def test_purge_discretized(self):
expected = (expected == 2).astype(float)
np.testing.assert_equal(out.Y, expected)

def test_meta_setting(self):
"""
Test if all conditions from all segments (attributes, class, meta)
stores correctly
"""
data = Table("iris")
data = Table.from_table(
Domain(
data.domain.attributes[:3],
data.domain.class_var,
data.domain.attributes[3:]
), data)
self.send_signal(self.widget.Inputs.data, data)

vars_ = [
data.domain.metas[0],
data.domain.attributes[0],
data.domain.class_var
]
cond = [0, 0, 0]
val = [(0, ), (0, ), (1, )]
conds = list(zip(vars_, cond, val))

self.widget.conditions = conds
self.assertListEqual([c[0] for c in self.widget.conditions], vars_)

# when sending new-same data conditions are restored from the context
self.send_signal(self.widget.Inputs.data, data)
self.assertListEqual([c[0] for c in self.widget.conditions], vars_)

def widget_with_context(self, domain, conditions):
ch = SelectRowsContextHandler()
context = ch.new_context(domain, *ch.encode_domain(domain))
Expand Down

0 comments on commit 804bc6a

Please sign in to comment.