Skip to content

Commit 20d04c0

Browse files
committed
OWKMeans: Add names to the output table with centroids
1 parent 21175b4 commit 20d04c0

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Orange/widgets/unsupervised/owkmeans.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,10 @@ def send_data(self):
512512
np.arange(km.k).reshape(km.k, 1),
513513
clust_scores))
514514
)
515+
if self.data.name == Table.name:
516+
centroids.name = "centroids"
517+
else:
518+
centroids.name = f"{self.data.name} centroids"
515519

516520
self.Outputs.annotated_data.send(new_table)
517521
self.Outputs.centroids.send(centroids)

Orange/widgets/unsupervised/tests/test_owkmeans.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,20 @@ def test_centroids_on_output(self, km_call):
217217
[[0, np.mean(np.arctan(np.arange(50) / 150)) / np.pi + 0.5],
218218
[1, np.mean(np.arctan(np.arange(50, 150) / 150)) / np.pi + 0.5],
219219
[2, 0], [3, 0]])
220+
self.assertEqual(out.name, "iris centroids")
220221

221222
def test_centroids_domain_on_output(self):
222223
widget = self.widget
223224
widget.optimize_k = False
224225
widget.k = 4
225226
heart_disease = Table("heart_disease")
227+
heart_disease.name = Table.name # untitled
226228
self.send_signal(widget.Inputs.data, heart_disease)
227229
self.commit_and_wait()
228230

229231
in_attrs = heart_disease.domain.attributes
230-
out_attrs = self.get_output(widget.Outputs.centroids).domain.attributes
232+
out = self.get_output(widget.Outputs.centroids)
233+
out_attrs = out.domain.attributes
231234
out_ids = {id(attr) for attr in out_attrs}
232235
for attr in in_attrs:
233236
self.assertEqual(
@@ -237,6 +240,7 @@ def test_centroids_domain_on_output(self):
237240
self.assertEqual(
238241
len(out_attrs),
239242
sum(attr.is_continuous or len(attr.values) for attr in in_attrs))
243+
self.assertEqual(out.name, "centroids")
240244

241245
class KMeansFail(Orange.clustering.KMeans):
242246
fail_on = set()

0 commit comments

Comments
 (0)