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] Distance Matrix: Fix crash on numeric meta vars as labels #5664

Merged
merged 1 commit into from
Nov 3, 2021
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
3 changes: 3 additions & 0 deletions Orange/widgets/unsupervised/owdistancematrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def set_labels(self, labels, variable=None, values=None):
self.values = values
if self.values is not None and not isinstance(self.variable,
StringVariable):
# Meta variables can be of type np.object
if values.dtype is not float:
values = values.astype(float)
self.label_colors = variable.palette.values_to_qcolors(values)
else:
self.label_colors = None
Expand Down
18 changes: 17 additions & 1 deletion Orange/widgets/unsupervised/tests/test_owdistancematrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from orangewidget.tests.base import GuiTest

from Orange.data import Table
from Orange.data import Table, Domain, ContinuousVariable, StringVariable
from Orange.distance import Euclidean
from Orange.widgets.tests.base import WidgetTest
from Orange.widgets.unsupervised.owdistancematrix import OWDistanceMatrix, \
Expand Down Expand Up @@ -57,6 +57,22 @@ def test_labels(self):
ac.activated.emit(idx)
self.assertIsNone(self.widget.tablemodel.label_colors)

def test_num_meta_labels(self):
x, y = (ContinuousVariable(c) for c in "xy")
s = StringVariable("s")
data = Table.from_list(
Domain([x], [], [y, s]),
[[0, 1, "a"],
[1, np.nan, "b"]]
)
distances = Euclidean(data)
self.widget.set_distances(distances)
ac = self.widget.annot_combo
idx = ac.model().indexOf(y)
ac.setCurrentIndex(idx)
ac.activated.emit(idx)
self.assertEqual(self.widget.tablemodel.labels, ["1", "?"])


class TestDelegates(GuiTest):
def test_delegate(self):
Expand Down