Skip to content

Commit

Permalink
Merge pull request #3339 from pavlin-policar/louvain-pca-slider-fix
Browse files Browse the repository at this point in the history
[FIX] Louvain Clustering: Do not invalidate output on PCA slider change with apply disabled
  • Loading branch information
lanzagar authored Nov 7, 2018
2 parents 89df563 + 13823f4 commit a0deeed
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Orange/widgets/unsupervised/owlouvainclustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def __init__(self):

def _invalidate_pca_projection(self):
self.pca_projection = None
if not self.apply_pca:
return

self._invalidate_graph()
self._set_modified(True)

Expand Down
32 changes: 32 additions & 0 deletions Orange/widgets/unsupervised/tests/test_owlouvain.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,38 @@ def test_do_not_recluster_on_same_data(self):
self.commit_and_wait()
self.assertEqual(call_count + 1, commit.call_count)

def test_only_recluster_when_necessary_pca_components_change(self):
# Compute clustering on some data
self.send_signal(self.widget.Inputs.data, self.iris)

# When PCA checkbox is ticked, any update to slider should invalidate results
self.widget.apply_pca_cbx.setChecked(True)
self.widget.pca_components_slider.setValue(2)
self.commit_and_wait()

with patch.object(self.widget, '_invalidate_output') as invalidate:
# Change slider value, this should invalidate output
self.widget.pca_components_slider.setValue(4)
self.commit_and_wait()
self.assertEqual(invalidate.call_count, 1)

with patch.object(self.widget, '_invalidate_output') as invalidate:
# Don't change slider value, this shouldn't do anything
self.widget.pca_components_slider.setValue(4)
self.commit_and_wait()
invalidate.assert_not_called()

# When PCA checkbox is not ticked updating the slider should have no effect
self.widget.apply_pca_cbx.setChecked(False)
self.widget.pca_components_slider.setValue(2)
self.commit_and_wait()

with patch.object(self.widget, '_invalidate_output') as invalidate:
# Change slider value, this should invalidate output
self.widget.pca_components_slider.setValue(4)
self.commit_and_wait()
invalidate.assert_not_called()

def test_invalidate(self):
# pylint: disable=protected-access
data = self.iris
Expand Down

0 comments on commit a0deeed

Please sign in to comment.