Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Detect duplicate names of variables in projections. #4550

Merged
merged 1 commit into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 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,17 @@ 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