Skip to content

Commit

Permalink
OWMDS: Output Flagged Data instead of Data
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Oct 13, 2016
1 parent 74af27d commit dfea890
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Orange/widgets/unsupervised/owmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
53 changes: 53 additions & 0 deletions Orange/widgets/unsupervised/tests/test_owmds.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit dfea890

Please sign in to comment.