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] SOM: Fix crash when clicking on empty canvas #4177

Merged
merged 2 commits into from
Nov 13, 2019
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
2 changes: 2 additions & 0 deletions Orange/widgets/unsupervised/owsom.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ def clear_selection(self):
self.redraw_selection()

def on_selection_change(self, selection, action=SomView.SelectionSet):
if self.data is None: # clicks on empty canvas
return
if self.selection is None:
self.selection = np.zeros(self.grid_cells.T.shape, dtype=np.int16)
if action == SomView.SelectionSet:
Expand Down
7 changes: 7 additions & 0 deletions Orange/widgets/unsupervised/tests/test_owsom.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def setUp(self):

def tearDown(self):
self.widget.onDeleteWidget()
super().tearDown()

def test_requires_continuous(self):
widget = self.widget
Expand Down Expand Up @@ -500,6 +501,12 @@ def selm(*cells):
widget.on_selection_change(selm((0, 0)), SomView.SelectionNewGroup)
np.testing.assert_equal(widget.selection, m)

@_patch_recompute_som
def test_on_selection_change_on_empty(self):
"""Test clicks on empty scene, when no data"""
widget = self.widget
widget.on_selection_change([])

@_patch_recompute_som
def test_output(self):
widget = self.widget
Expand Down