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] OWDistributions: Fix binning of meta attributes #2068

Merged
merged 1 commit into from
Mar 3, 2017
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: 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)