Skip to content

Commit

Permalink
OWDistances: Do not show messages when data is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Nov 3, 2016
1 parent f2c5f72 commit 3520290
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Orange/widgets/unsupervised/owdistances.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ def commit(self):
self.send("Distances", self.compute_distances(metric, self.data))

def compute_distances(self, metric, data):
self.clear_messages()

if data is None:
return

self.clear_messages()

if issparse(data.X) and not metric.supports_sparse:
self.Error.dense_metric_sparse_data()
return
Expand Down
42 changes: 42 additions & 0 deletions Orange/widgets/unsupervised/tests/test_owdistances.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring
import numpy as np

from Orange.data import Table
from Orange.distance import MahalanobisDistance
from Orange.widgets.unsupervised.owdistances import OWDistances, METRICS
from Orange.widgets.tests.base import WidgetTest


class TestOWDistances(WidgetTest):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.iris = Table("iris")
cls.titanic = Table("titanic")

def setUp(self):
self.widget = self.create_widget(OWDistances)

def test_distance_combo(self):
"""Check distances when the metric changes"""
self.assertEqual(self.widget.metrics_combo.count(), len(METRICS))
self.send_signal("Data", self.iris)
for i, metric in enumerate(METRICS):
if isinstance(metric, MahalanobisDistance):
metric.fit(self.iris)
self.widget.metrics_combo.activated.emit(i)
self.widget.metrics_combo.setCurrentIndex(i)
self.send_signal("Data", self.iris)
np.testing.assert_array_equal(
metric(self.iris), self.get_output("Distances"))

def test_error_message(self):
"""Check if error message appears and then disappears when
data is removed from input"""
self.send_signal("Data", self.iris)
self.assertFalse(self.widget.Error.no_continuous_features.is_shown())
self.send_signal("Data", self.titanic)
self.assertTrue(self.widget.Error.no_continuous_features.is_shown())
self.send_signal("Data", None)
self.assertFalse(self.widget.Error.no_continuous_features.is_shown())

0 comments on commit 3520290

Please sign in to comment.