From 44d2e0855f0dcde8d8ef130eaa384fef8bc177a7 Mon Sep 17 00:00:00 2001 From: janezd Date: Thu, 2 Mar 2017 20:59:52 +0100 Subject: [PATCH] OWDistributions: Fix discretization of meta attributes --- Orange/widgets/visualize/owdistributions.py | 6 ++++-- .../visualize/tests/test_owdistributions.py | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Orange/widgets/visualize/owdistributions.py b/Orange/widgets/visualize/owdistributions.py index 81e08ea1994..364f479becd 100644 --- a/Orange/widgets/visualize/owdistributions.py +++ b/Orange/widgets/visualize/owdistributions.py @@ -287,10 +287,12 @@ def _setup(self): if self.var is None: return if self.disc_cont: - data = self.data[:, (self.var, self.cvar) if self.cvar else self.var ] + domain = Orange.data.Domain( + [self.var, self.cvar] if self.cvar else [self.var]) + data = Orange.data.Table(domain, data) disc = Orange.preprocess.discretize.EqualWidth(n=self.bins[self.smoothing_index]) data = Orange.preprocess.Discretize(method=disc, remove_const=False)(data) - self.var = (list(data.domain) + list(data.domain.metas))[0] + self.var = data.domain[0] self.set_left_axis_name() self.enable_disable_rel_freq() if self.cvar: diff --git a/Orange/widgets/visualize/tests/test_owdistributions.py b/Orange/widgets/visualize/tests/test_owdistributions.py index 95f8c4707c8..1f4540d1c6d 100644 --- a/Orange/widgets/visualize/tests/test_owdistributions.py +++ b/Orange/widgets/visualize/tests/test_owdistributions.py @@ -1,7 +1,7 @@ # Test methods with long descriptive names can omit docstrings # pylint: disable=missing-docstring -from Orange.data import Table +from Orange.data import Table, Domain, DiscreteVariable from Orange.data.table import dataset_dirs from Orange.tests import test_dirname from Orange.widgets.tests.base import WidgetTest @@ -43,3 +43,17 @@ def test_remove_data(self): self.send_signal("Data", None) self.assertEqual(self.widget.cb_prob.count(), 0) self.assertEqual(self.widget.groupvarview.count(), 0) + + def test_discretize_meta(self): + """The widget discretizes continuous meta attributes""" + domain = self.iris.domain + mdomain = Domain(domain.attributes[:-1], domain.class_var, + metas=domain.attributes[-1:]) + miris = Table(mdomain, self.iris) + self.send_signal("Data", miris) + widget = self.widget + widget.disc_cont = True + widget.varview.selectionModel().select( + widget.varview.model().index(4, 0)) + self.assertIsInstance(widget.var, DiscreteVariable) + self.assertEqual(widget.var.name, mdomain.metas[0].name)