Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Heatmap: Split by missing values #4686

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Orange/widgets/visualize/owheatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,15 @@ def _make_parts(self, data, group_var=None):
_col_data = table_column_data(data, group_var)
row_indices = [np.flatnonzero(_col_data == i)
for i in range(len(group_var.values))]

row_groups = [RowPart(title=name, indices=ind,
cluster=None, cluster_ordered=None)
for name, ind in zip(group_var.values, row_indices)]
if np.any(_col_data.mask):
row_groups.append(RowPart(
title="N/A", indices=np.flatnonzero(_col_data.mask),
cluster=None, cluster_ordered=None
))
else:
row_groups = [RowPart(title=None, indices=range(0, len(data)),
cluster=None, cluster_ordered=None)]
Expand Down
12 changes: 11 additions & 1 deletion Orange/widgets/visualize/tests/test_owheatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def setUpClass(cls):

cls.housing = Table("housing")
cls.titanic = Table("titanic")
cls.brown_selected = Table("brown-selected")

cls.signal_name = "Data"
cls.signal_data = cls.data
Expand Down Expand Up @@ -211,7 +212,7 @@ def test_saved_selection(self):
self.assertEqual(len(self.get_output(w.Outputs.selected_data)), 21)

def test_set_split_var(self):
data = Table("brown-selected")
data = self.brown_selected[::3]
w = self.widget
self.send_signal(self.widget.Inputs.data, data, widget=w)
self.assertIs(w.split_by_var, data.domain.class_var)
Expand All @@ -221,6 +222,15 @@ def test_set_split_var(self):
self.assertIs(w.split_by_var, None)
self.assertEqual(len(w.parts.rows), 1)

def test_set_split_var_missing(self):
data = self.brown_selected[::3].copy()
data.Y[::5] = np.nan
w = self.widget
self.send_signal(self.widget.Inputs.data, data, widget=w)
self.assertIs(w.split_by_var, data.domain.class_var)
self.assertEqual(len(w.parts.rows),
len(data.domain.class_var.values) + 1)

def test_palette_centering(self):
data = np.arange(2).reshape(-1, 1)
table = Table.from_numpy(Domain([ContinuousVariable("y")]), data)
Expand Down
13 changes: 4 additions & 9 deletions Orange/widgets/visualize/utils/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,21 +368,18 @@ def setHeatmaps(self, parts: 'Parts') -> None:
row_dendrograms: List[Optional[DendrogramWidget]] = [None] * N
right_side_colors: List[Optional[GraphicsPixmapWidget]] = [None] * N

ncols = sum(c.size for c in parts.columns)
nrows = sum(r.size for r in parts.rows)
data = parts.data
if parts.col_names is None:
col_names = np.full(ncols, "", dtype=object)
col_names = np.full(data.shape[1], "", dtype=object)
else:
col_names = np.asarray(parts.col_names, dtype=object)
if parts.row_names is None:
row_names = np.full(nrows, "", dtype=object)
row_names = np.full(data.shape[0], "", dtype=object)
else:
row_names = np.asarray(parts.row_names, dtype=object)

assert data.shape == (nrows, ncols)
assert len(col_names) == ncols
assert len(row_names) == nrows
assert len(col_names) == data.shape[1]
assert len(row_names) == data.shape[0]

for i, rowitem in enumerate(parts.rows):
if rowitem.title:
Expand Down Expand Up @@ -710,8 +707,6 @@ def set_visible(item: GraphicsPixmapWidget):
legend_container.setVisible(True)

parts = self.parts.rows
nrows = sum(p.size for p in parts)
assert len(data) == nrows
for p, item in zip(parts, items):
if item is not None:
subset = data[p.normalized_indices]
Expand Down