Skip to content

Commit

Permalink
Merge pull request #2068 from janezd/fix-distribution-discretize-meta
Browse files Browse the repository at this point in the history
[FIX] OWDistributions: Fix binning of meta attributes
  • Loading branch information
lanzagar authored Mar 3, 2017
2 parents eb53e99 + 44d2e08 commit 2dcb66f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Orange/widgets/visualize/owdistributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 15 additions & 1 deletion Orange/widgets/visualize/tests/test_owdistributions.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 2dcb66f

Please sign in to comment.