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] Louvain Clustering: Do not invalidate output on PCA slider change with apply disabled #3339

Merged
merged 1 commit into from
Nov 7, 2018
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
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