Skip to content

Commit

Permalink
Merge pull request #6887 from janezd/hc-more-clusters
Browse files Browse the repository at this point in the history
Hierarchical clustering: Allow more than 20 clusters in Top n spin
  • Loading branch information
lanzagar authored Sep 20, 2024
2 parents e67cddb + 2a6f878 commit 2c966b7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Orange/widgets/unsupervised/owhierarchicalclustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ class Warning(widget.OWWidget.Warning):
Msg("Subset data refers to a different table")
pruning_disables_colors = \
Msg("Pruned cluster doesn't show colors and indicate subset")
many_clusters = \
Msg("Variables with too many values may "
"degrade the performance of downstream widgets.")

#: Stored (manual) selection state (from a saved workflow) to restore.
__pending_selection_restore = None # type: Optional[SelectionState]
Expand Down Expand Up @@ -361,7 +364,7 @@ def on_annotation_changed(value):
2, 0
)
self.top_n_spin = gui.spin(
self.selection_box, self, "top_n", 1, 20,
self.selection_box, self, "top_n", 1, 1000,
controlWidth=spin_width, alignment=Qt.AlignRight,
callback=self._top_n_changed, addToLayout=False)
self.top_n_spin.lineEdit().returnPressed.connect(self._top_n_return)
Expand Down Expand Up @@ -766,6 +769,7 @@ def _invalidate_pruning(self):
@gui.deferred
def commit(self):
items = getattr(self.matrix, "items", self.items)
self.Warning.many_clusters.clear()
if not items:
self.Outputs.selected_data.send(None)
self.Outputs.annotated_data.send(None)
Expand All @@ -778,6 +782,8 @@ def commit(self):

maps = [indices[node.value.first:node.value.last]
for node in selection]
if len(maps) > 20:
self.Warning.many_clusters()

selected_indices = list(chain(*maps))

Expand Down
19 changes: 19 additions & 0 deletions Orange/widgets/unsupervised/tests/test_owhierarchicalclustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,22 @@ def test_column_distances(self):
annotated = [(a.name, a.attributes['cluster']) for a in o.domain.attributes]
self.assertEqual(annotated, [('sepal length', 1), ('petal width', 2),
('sepal width', 3), ('petal length', 3)])

def test_many_values_warning(self):
w = self.widget

self.send_signal(self.widget.Inputs.distances, self.distances)
w.top_n = 21
w.selection_box.buttons[2].click()
self.assertTrue(w.Warning.many_clusters.is_shown())

w.top_n = 20
w.selection_box.buttons[2].click()
self.assertFalse(w.Warning.many_clusters.is_shown())

w.top_n = 21
w.selection_box.buttons[2].click()
self.assertTrue(w.Warning.many_clusters.is_shown())

self.send_signal(self.widget.Inputs.distances, None)
self.assertFalse(w.Warning.many_clusters.is_shown())

0 comments on commit 2c966b7

Please sign in to comment.