Skip to content

Commit

Permalink
Merge pull request #2521 from jerneju/silhouetteplot-valuememory
Browse files Browse the repository at this point in the history
[FIX] Silhouette Plot: another memory error
  • Loading branch information
thocevar authored Aug 18, 2017
2 parents 63109a2 + 095246a commit 77c5aa2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
8 changes: 5 additions & 3 deletions Orange/widgets/visualize/owsilhouetteplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Error(widget.OWWidget.Error):
need_two_clusters = Msg("Need at least two non-empty clusters")
singleton_clusters_all = Msg("All clusters are singletons")
memory_error = Msg("Not enough memory")
value_error = Msg("Distances could not be computed: '{}'")

class Warning(widget.OWWidget.Warning):
missing_cluster_assignment = Msg(
Expand Down Expand Up @@ -267,6 +268,9 @@ def _update(self):
except MemoryError:
self.Error.memory_error()
return
except ValueError as err:
self.Error.value_error(str(err))
return

self._update_labels()

Expand All @@ -278,9 +282,7 @@ def _reset_all(self):
self._clear_scene()

def _clear_messages(self):
self.Error.memory_error.clear()
self.Error.singleton_clusters_all.clear()
self.Error.need_two_clusters.clear()
self.Error.clear()
self.Warning.missing_cluster_assignment.clear()

def _update_labels(self):
Expand Down
26 changes: 16 additions & 10 deletions Orange/widgets/visualize/tests/test_owsilhouetteplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,23 @@ def test_memory_error(self):
"""
Handling memory error.
GH-2336
Handling value error as well. This value error is in a relation with memory error.
GH-2521
"""
data = Orange.data.Table("iris")[::3]
self.assertFalse(self.widget.Error.memory_error.is_shown())
with unittest.mock.patch(
"numpy.asarray",
side_effect=MemoryError):
self.widget._matrix = None
self.widget.data = data
self.widget._effective_data = data
self.widget._update()
self.assertTrue(self.widget.Error.memory_error.is_shown())
for i, side_effect in enumerate([MemoryError, ValueError]):
data = Orange.data.Table("iris")[::3]
self.send_signal(self.widget.Inputs.data, data)
self.assertFalse(self.widget.Error.memory_error.is_shown())
self.assertFalse(self.widget.Error.value_error.is_shown())
with unittest.mock.patch(
"numpy.asarray",
side_effect=side_effect):
self.widget._matrix = None
self.widget.data = data
self.widget._effective_data = data
self.widget._update()
self.assertTrue(self.widget.Error.memory_error.is_shown() != i)
self.assertTrue(self.widget.Error.value_error.is_shown() == i)

def test_bad_data_range(self):
"""
Expand Down

0 comments on commit 77c5aa2

Please sign in to comment.