Skip to content

Commit

Permalink
OWLouvainClustering: fix num_neighbour setting that is not saving cor…
Browse files Browse the repository at this point in the history
…rectly
  • Loading branch information
PrimozGodec committed Nov 13, 2019
1 parent a07ba19 commit a533e5d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
2 changes: 0 additions & 2 deletions Orange/widgets/unsupervised/owlouvainclustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down
33 changes: 32 additions & 1 deletion Orange/widgets/unsupervised/tests/test_owlouvain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit a533e5d

Please sign in to comment.