Skip to content

Commit

Permalink
Fix duplicate_names detection in projections.
Browse files Browse the repository at this point in the history
Apply the requested changes.

Fix pylint error

Add code

Fix projection data domain duplicate checking.

Add test for unique name after linearprojection components added.
  • Loading branch information
NejcDebevec committed Mar 24, 2020
1 parent 64c51ca commit 7eb23af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 13 additions & 1 deletion Orange/widgets/visualize/tests/test_owlinearprojection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from AnyQt.QtCore import QItemSelectionModel

from Orange.data import Table, Domain, DiscreteVariable
from Orange.data import Table, Domain, DiscreteVariable, ContinuousVariable
from Orange.widgets.settings import Context
from Orange.widgets.tests.base import (
WidgetTest, WidgetOutputsTestMixin, datasets,
Expand Down Expand Up @@ -185,6 +185,18 @@ def test_two_classes_dataset(self):
self.send_signal(self.widget.Inputs.data, Table("heart_disease"))
self.assertFalse(self.widget.radio_placement.buttons[1].isEnabled())

def test_unique_name(self):
data = Table("iris")
new = ContinuousVariable("C-y")
d = Table.from_numpy(Domain(list(data.domain.attributes[:3])+[new],
class_vars=data.domain.class_vars), data.X,
data.Y)
self.send_signal(self.widget.Inputs.data, d)
output = self.get_output(self.widget.Outputs.annotated_data)
metas = ["C-x (1)", "C-y (1)", "Selected"]
self.assertEqual([meta.name for meta in
output.domain.metas], metas)


class LinProjVizRankTests(WidgetTest):
"""
Expand Down
10 changes: 9 additions & 1 deletion Orange/widgets/visualize/utils/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,18 @@ def _manual_move_finish(self, anchor_idx, x, y):
def _get_projection_data(self):
if self.data is None or self.projection is None:
return None
proposed = [a.name for a in self.projection.domain.attributes]
names = get_unique_names(self.data.domain, proposed)

if proposed != names:
attributes = tuple([attr.copy(name=name) for name, attr in
zip(names, self.projection.domain.attributes)])
else:
attributes = self.projection.domain.attributes
return self.data.transform(
Domain(self.data.domain.attributes,
self.data.domain.class_vars,
self.data.domain.metas + self.projection.domain.attributes))
self.data.domain.metas + attributes))

def commit(self):
super().commit()
Expand Down

0 comments on commit 7eb23af

Please sign in to comment.