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] MDS: Fix crashes when feeding column distances #3583

Merged
merged 2 commits into from
Feb 15, 2019
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
15 changes: 12 additions & 3 deletions Orange/widgets/unsupervised/owmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pyqtgraph as pg

from Orange.data import ContinuousVariable, Domain, Table
from Orange.data import ContinuousVariable, Domain, Table, StringVariable
from Orange.distance import Euclidean
from Orange.misc import DistMatrix
from Orange.projection.manifold import torgerson, MDS
Expand Down Expand Up @@ -269,8 +269,11 @@ def _initialize(self):

if self.matrix is not None:
self.effective_matrix = self.matrix
if self.matrix.axis == 0 and self.data is self.matrix_data:
self.data = None
if self.matrix.axis == 0 and self.data is not None \
and self.data is self.matrix_data:
names = [[attr.name] for attr in self.data.domain.attributes]
domain = Domain([], metas=[StringVariable("labels")])
self.data = Table(domain, names)
elif self.data.domain.attributes:
preprocessed_data = MDS().preprocess(self.data)
self.effective_matrix = Euclidean(preprocessed_data)
Expand All @@ -290,6 +293,12 @@ def _initialize(self):
self.clear()
self.graph.set_effective_matrix(self.effective_matrix)

def init_attr_values(self):
super().init_attr_values()
if self.matrix is not None and self.matrix.axis == 0 and \
self.data is not None and len(self.data):
self.attr_label = self.data.domain["labels"]

def _toggle_run(self):
if self.__state == OWMDS.Running:
self.stop()
Expand Down
16 changes: 16 additions & 0 deletions Orange/widgets/unsupervised/tests/test_owmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,22 @@ def test_saved_matrix_and_data(self):
self.send_signal(self.widget.Inputs.data, towns_data)
self.assertIn(towns_data.domain["label"], attr_label.model())

def test_matrix_columns_tooltip(self):
dist = Euclidean(self.data, axis=0)
self.send_signal(self.widget.Inputs.distances, dist)
self.assertIn("sepal length", self.widget.get_tooltip([0]))

def test_matrix_columns_labels(self):
dist = Euclidean(self.data, axis=0)
self.send_signal(self.widget.Inputs.distances, dist)
simulate.combobox_activate_index(self.widget.controls.attr_label, 2)

def test_matrix_columns_default_label(self):
dist = Euclidean(self.data, axis=0)
self.send_signal(self.widget.Inputs.distances, dist)
label_text = self.widget.controls.attr_label.currentText()
self.assertEqual(label_text, "labels")


if __name__ == "__main__":
unittest.main()