From d55d65254e37e651a0314a70d5543454f3926cc8 Mon Sep 17 00:00:00 2001 From: astaric Date: Tue, 20 Feb 2018 10:22:02 +0100 Subject: [PATCH] heatmap: do not crash on all zero column --- Orange/widgets/visualize/owheatmap.py | 2 ++ Orange/widgets/visualize/tests/test_owheatmap.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Orange/widgets/visualize/owheatmap.py b/Orange/widgets/visualize/owheatmap.py index 4e83d181896..84584c1cbf4 100644 --- a/Orange/widgets/visualize/owheatmap.py +++ b/Orange/widgets/visualize/owheatmap.py @@ -822,6 +822,8 @@ def cluster_columns(self, data, parts): if need_dist: data = Orange.distance._preprocess(data) matrix = Orange.distance.PearsonR(data, axis=0) + # nan values break clustering below + matrix = np.nan_to_num(matrix) if cluster is None: cluster = hierarchical.dist_matrix_clustering(matrix) diff --git a/Orange/widgets/visualize/tests/test_owheatmap.py b/Orange/widgets/visualize/tests/test_owheatmap.py index 5974451e867..5e2e23aa690 100644 --- a/Orange/widgets/visualize/tests/test_owheatmap.py +++ b/Orange/widgets/visualize/tests/test_owheatmap.py @@ -19,7 +19,7 @@ def setUpClass(cls): cls.signal_data = cls.data def setUp(self): - self.widget = self.create_widget(OWHeatMap) + self.widget = self.create_widget(OWHeatMap) # type: OWHeatMap def test_input_data(self): """Check widget's data with data on the input""" @@ -117,3 +117,12 @@ def test_data_column_nans(self): table = datasets.data_one_column_nans() self.widget.controls.merge_kmeans.setChecked(True) self.send_signal(self.widget.Inputs.data, table) + + def test_cluster_column_on_all_zero_column(self): + # Pearson distance used for clustering of columns does not + # handle all zero columns well + iris = Table("iris") + iris[:, 0] = 0 + + self.widget.col_clustering = True + self.widget.set_dataset(iris)