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

[ENH] CreateClass: data info displayed in the status bar #4625

Merged
merged 1 commit into from
Apr 14, 2020
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
13 changes: 13 additions & 0 deletions Orange/widgets/data/owcreateclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from Orange.widgets.settings import DomainContextHandler, ContextSetting
from Orange.widgets.utils.itemmodels import DomainModel
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.widget import Msg, Input, Output


Expand Down Expand Up @@ -225,6 +226,9 @@ def __init__(self):
gui.button(box, self, "Apply", autoDefault=False, width=180,
callback=self.apply)

self.info.set_input_summary(self.info.NoInput)
self.info.set_output_summary(self.info.NoOutput)

# TODO: Resizing upon changing the number of rules does not work
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum)

Expand All @@ -250,12 +254,16 @@ def set_data(self, data):
self.closeContext()
self.rules = {}
self.data = data
summary = len(data) if data else self.info.NoInput
details = format_summary_details(data) if data else ""
self.info.set_input_summary(summary, details)
model = self.controls.attribute.model()
model.set_domain(data and data.domain)
self.Warning.no_nonnumeric_vars(shown=data is not None and not model)
if not model:
self.attribute = None
self.Outputs.data.send(None)
self.info.set_output_summary(self.info.NoOutput)
return
self.attribute = model[0]
self.openContext(data)
Expand Down Expand Up @@ -462,6 +470,7 @@ def apply(self):
self.class_name = self.class_name.strip()
if not self.attribute:
self.Outputs.data.send(None)
self.info.set_output_summary(self.info.NoOutput)
return
domain = self.data.domain
if not self.class_name:
Expand All @@ -470,11 +479,15 @@ def apply(self):
self.Error.class_name_duplicated()
if not self.class_name or self.class_name in domain:
self.Outputs.data.send(None)
self.info.set_output_summary(self.info.NoOutput)
return
new_class = self._create_variable()
new_domain = Domain(
domain.attributes, new_class, domain.metas + domain.class_vars)
new_data = self.data.transform(new_domain)
summary = len(new_data) if new_data is not None else self.info.NoOutput
details = format_summary_details(new_data) if new_data is not None else ""
self.info.set_output_summary(summary, details)
self.Outputs.data.send(new_data)

def _create_variable(self):
Expand Down
33 changes: 32 additions & 1 deletion Orange/widgets/data/tests/test_owcreateclass.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring
# pylint: disable=missing-docstring, protected-access
import unittest
from unittest.mock import patch

Expand All @@ -10,6 +10,7 @@
OWCreateClass,
map_by_substring, ValueFromStringSubstring, ValueFromDiscreteSubstring)
from Orange.widgets.tests.base import WidgetTest
from Orange.widgets.utils.state_summary import format_summary_details


class TestHelpers(unittest.TestCase):
Expand Down Expand Up @@ -405,6 +406,36 @@ def test_same_class(self):
self.get_output(widget2.Outputs.data, widget=widget2).domain.class_var
)

def test_summary(self):
"""Check if status bar is updated when data is received"""
data = self.zoo
info = self.widget.info
no_input, no_output = "No data on input", "No data on output"

self.send_signal(self.widget.Inputs.data, data)
summary, details = f"{len(data)}", format_summary_details(data)
self.assertEqual(info._StateInfo__input_summary.brief, summary)
self.assertEqual(info._StateInfo__input_summary.details, details)
output = self.get_output(self.widget.Outputs.data)
summary, details = f"{len(output)}", format_summary_details(output)
self.assertEqual(info._StateInfo__output_summary.brief, summary)
self.assertEqual(info._StateInfo__output_summary.details, details)

self.send_signal(self.widget.Inputs.data, data)
self.widget.class_name = ""
self.widget.apply()
self.assertEqual(info._StateInfo__output_summary.brief, "")
self.assertEqual(info._StateInfo__output_summary.details, no_output)
self.widget.class_name = "type"
self.widget.apply()
self.assertEqual(info._StateInfo__output_summary.brief, "")
self.assertEqual(info._StateInfo__output_summary.details, no_output)

self.send_signal(self.widget.Inputs.data, None)
self.assertEqual(info._StateInfo__input_summary.brief, "")
self.assertEqual(info._StateInfo__input_summary.details, no_input)
self.assertEqual(info._StateInfo__output_summary.brief, "")
self.assertEqual(info._StateInfo__output_summary.details, no_output)

if __name__ == "__main__":
unittest.main()