Skip to content

Commit

Permalink
Heat map: Cannot cluster a single instance
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Aug 23, 2019
1 parent bf6edbe commit 94811c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Orange/widgets/visualize/owheatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ def __new__(cls, title, indices, sortindices, cluster=None,
cluster, cluster_ordered)

@property
def is_empty(self):
def can_cluster(self):
if isinstance(self.indices, slice):
return (self.indices.stop - self.indices.start) == 0
return (self.indices.stop - self.indices.start) > 1
else:
return len(self.indices) == 0
return len(self.indices) > 1

@property
def cluster_ord(self):
Expand Down Expand Up @@ -794,7 +794,7 @@ def cluster_rows(self, data, parts):
else:
cluster_ord = None

if not row.is_empty:
if row.can_cluster:
need_dist = cluster is None or cluster_ord is None
if need_dist:
subset = data[row.indices]
Expand Down
9 changes: 8 additions & 1 deletion Orange/widgets/visualize/tests/test_owheatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
from sklearn.exceptions import ConvergenceWarning

from Orange.data import Table, Domain, ContinuousVariable
from Orange.data import Table, Domain, ContinuousVariable, DiscreteVariable
from Orange.preprocess import Continuize
from Orange.widgets.visualize.owheatmap import OWHeatMap
from Orange.widgets.tests.base import WidgetTest, WidgetOutputsTestMixin, datasets
Expand Down Expand Up @@ -168,3 +168,10 @@ def test_use_enough_colors(self):
colors[r] = c.red(), c.green(), c.blue()
unique_colors = len(np.unique(colors, axis=0))
self.assertLessEqual(len(data)*self.widget.threshold_low, unique_colors)

def test_cls_with_single_instance(self):
table = Table(Domain([ContinuousVariable("c1")],
[DiscreteVariable("c2", values=["a", "b"])]),
np.array([[1], [2], [3]]), np.array([[0], [0], [1]]))
self.send_signal(self.widget.Inputs.data, table)
self.widget.row_check.setChecked(True)

0 comments on commit 94811c8

Please sign in to comment.