From a533e5d4a9713bab173ab27517756d9af527c96e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Primo=C5=BE=20Godec?=
Date: Wed, 13 Nov 2019 16:00:59 +0100
Subject: [PATCH] OWLouvainClustering: fix num_neighbour setting that is not
saving correctly
---
.../unsupervised/owlouvainclustering.py | 2 --
.../unsupervised/tests/test_owlouvain.py | 33 ++++++++++++++++++-
2 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/Orange/widgets/unsupervised/owlouvainclustering.py b/Orange/widgets/unsupervised/owlouvainclustering.py
index 5f02c426cee..fc59219c03e 100644
--- a/Orange/widgets/unsupervised/owlouvainclustering.py
+++ b/Orange/widgets/unsupervised/owlouvainclustering.py
@@ -431,10 +431,8 @@ def set_data(self, data):
# Can't have more PCA components than the number of attributes
n_attrs = len(data.domain.attributes)
self.pca_components_slider.setMaximum(min(_MAX_PCA_COMPONENTS, n_attrs))
- self.pca_components_slider.setValue(min(_DEFAULT_PCA_COMPONENTS, n_attrs))
# Can't have more k neighbors than there are data points
self.k_neighbors_spin.setMaximum(min(_MAX_K_NEIGBOURS, len(data) - 1))
- self.k_neighbors_spin.setValue(min(_DEFAULT_K_NEIGHBORS, len(data) - 1))
self.info_label.setText("Clustering not yet run.")
diff --git a/Orange/widgets/unsupervised/tests/test_owlouvain.py b/Orange/widgets/unsupervised/tests/test_owlouvain.py
index ee3b7bc1c67..e7aaeee3c19 100644
--- a/Orange/widgets/unsupervised/tests/test_owlouvain.py
+++ b/Orange/widgets/unsupervised/tests/test_owlouvain.py
@@ -5,7 +5,7 @@
from Orange.data import Table, Domain, ContinuousVariable
from Orange.preprocess import Normalize
from Orange.widgets.tests.base import WidgetTest
-from Orange.widgets.tests.utils import table_dense_sparse
+from Orange.widgets.tests.utils import table_dense_sparse, simulate
from Orange.widgets.unsupervised.owlouvainclustering import OWLouvainClustering
from sklearn.utils import check_random_state
@@ -234,3 +234,34 @@ def _compute_clustering(data):
dense_result = _compute_clustering(dense_data)
sparse_result = _compute_clustering(sparse_data)
np.testing.assert_equal(dense_result.metas, sparse_result.metas)
+
+ def test_settings_correctly_restored(self):
+ """
+ This test checks if contextsettings are correctly restored after
+ dataset changed.
+ """
+ w = self.widget
+
+ self.send_signal(w.Inputs.data, self.iris)
+ w.controls.apply_pca.setChecked(False)
+ w.controls.pca_components.setValue(2)
+ simulate.combobox_activate_item(w.controls.metric_idx, "Manhattan")
+ w.controls.normalize.setChecked(False)
+ w.controls.k_neighbors.setValue(4)
+ w.controls.resolution.setValue(0.5)
+
+ self.send_signal(w.Inputs.data, Table("zoo"))
+ w.controls.apply_pca.setChecked(True)
+ w.controls.pca_components.setValue(3)
+ simulate.combobox_activate_item(w.controls.metric_idx, "Euclidean")
+ w.controls.normalize.setChecked(True)
+ w.controls.k_neighbors.setValue(5)
+ w.controls.resolution.setValue(1)
+
+ self.send_signal(w.Inputs.data, self.iris)
+ self.assertFalse(w.apply_pca)
+ self.assertEqual(2, w.pca_components)
+ self.assertEqual(1, w.metric_idx)
+ self.assertFalse(w.normalize)
+ self.assertEqual(4, w.k_neighbors)
+ self.assertEqual(0.5, w.resolution)