diff --git a/Orange/widgets/unsupervised/owmds.py b/Orange/widgets/unsupervised/owmds.py index d42fcf082a3..f7eac289f32 100644 --- a/Orange/widgets/unsupervised/owmds.py +++ b/Orange/widgets/unsupervised/owmds.py @@ -19,6 +19,7 @@ import Orange.distance from Orange.data.domain import filter_visible import Orange.misc +from Orange.misc.flagged_data import create_flagged_table, FLAGGED_SIGNAL_NAME from Orange.widgets import widget, gui, settings from Orange.widgets.utils import colorpalette, itemmodels from Orange.widgets.utils.sql import check_sql_input @@ -101,7 +102,7 @@ class OWMDS(OWWidget): ("Data Subset", Orange.data.Table, "set_subset_data")] outputs = [("Selected Data", Orange.data.Table, widget.Default), - ("Data", Orange.data.Table)] + (FLAGGED_SIGNAL_NAME, Orange.data.Table)] #: Initialization type PCA, Random = 0, 1 @@ -1041,13 +1042,14 @@ def commit(self): elif self.output_embedding_role == OWMDS.MetaRole: output.metas[:, -2:] = embedding.X - self.send("Data", output) if output is not None and self._selection_mask is not None and \ numpy.any(self._selection_mask): subset = output[self._selection_mask] else: subset = None self.send("Selected Data", subset) + self.send(FLAGGED_SIGNAL_NAME, + create_flagged_table(output, self._selection_mask)) def onDeleteWidget(self): super().onDeleteWidget() diff --git a/Orange/widgets/unsupervised/tests/test_owmds.py b/Orange/widgets/unsupervised/tests/test_owmds.py new file mode 100644 index 00000000000..2c4168a4778 --- /dev/null +++ b/Orange/widgets/unsupervised/tests/test_owmds.py @@ -0,0 +1,53 @@ +# Test methods with long descriptive names can omit docstrings +# pylint: disable=missing-docstring +import random +import numpy as np +from PyQt4.QtCore import QEvent +from Orange.data import Table +from Orange.misc.flagged_data import FLAGGED_SIGNAL_NAME, FLAGGED_FEATURE_NAME +from Orange.distance import Euclidean +from Orange.widgets.unsupervised.owmds import OWMDS +from Orange.widgets.tests.base import WidgetTest + + +class TestOWMDS(WidgetTest): + def setUp(self): + self.widget = self.create_widget(OWMDS) + self.iris = Table("iris") + self.iris_distances = Euclidean(self.iris) + + def test_outputs(self): + self.send_signal("Distances", self.iris_distances) + self.widget.customEvent(QEvent(QEvent.User)) + self.widget.commit() + + # check selected data output + self.assertIsNone(self.get_output("Selected Data")) + + # check flagged data output + flagged = self.get_output(FLAGGED_SIGNAL_NAME) + self.assertEqual(0, np.sum([i[FLAGGED_FEATURE_NAME] for i in flagged])) + + # select data points + points = random.sample(range(0, len(self.iris)), 20) + self.widget.select_indices(points) + self.widget.commit() + + # check selected data output + selected = self.get_output("Selected Data") + self.assertEqual(len(selected), len(points)) + + # check flagged data output + flagged = self.get_output(FLAGGED_SIGNAL_NAME) + self.assertEqual(len(selected), + np.sum([i[FLAGGED_FEATURE_NAME] for i in flagged])) + + # compare selected and flagged data domains + selected_vars = selected.domain.variables + selected.domain.metas + flagged_vars = flagged.domain.variables + flagged.domain.metas + self.assertTrue(all((var in flagged_vars for var in selected_vars))) + + # check output when data is removed + self.send_signal("Distances", None) + self.assertIsNone(self.get_output("Selected Data")) + self.assertIsNone(self.get_output(FLAGGED_SIGNAL_NAME))