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] OWDiscretize: data info displayed in status bar #4331

Merged
merged 1 commit into from
Jan 17, 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
8 changes: 8 additions & 0 deletions Orange/widgets/data/owdiscretize.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ def _intbox(parent, attr, callback):

self._update_spin_positions()

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


@Inputs.data
def set_data(self, data):
Expand All @@ -257,7 +260,9 @@ def set_data(self, data):
self._restore(self.saved_var_states)
# Complete the induction of cut points
self._update_points()
self.info.set_input_summary(len(data))
else:
self.info.set_input_summary(self.info.NoInput)
self._clear()
self.unconditional_commit()

Expand Down Expand Up @@ -478,6 +483,9 @@ def commit(self):
if self.data is not None and len(self.data):
domain = self.discretized_domain()
output = self.data.transform(domain)
self.info.set_output_summary(len(output))
else:
self.info.set_output_summary(self.info.NoOutput)
self.Outputs.data.send(output)

def storeSpecificSettings(self):
Expand Down
24 changes: 23 additions & 1 deletion Orange/widgets/data/tests/test_owdiscretize.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring
# pylint: disable=missing-docstring,unsubscriptable-object
from unittest.mock import Mock

from Orange.data import Table
from Orange.widgets.data.owdiscretize import OWDiscretize
from Orange.widgets.tests.base import WidgetTest
from orangewidget.widget import StateInfo


class TestOWDiscretize(WidgetTest):
Expand All @@ -17,3 +20,22 @@ def test_empty_data(self):
self.send_signal(self.widget.Inputs.data,
Table.from_domain(data.domain))
widget.unconditional_commit()

def test_summary(self):
"""Check if status bar is updated when data is received"""
input_sum = self.widget.info.set_input_summary = Mock()
output_sum = self.widget.info.set_output_summary = Mock()

data = Table("iris")
self.send_signal(self.widget.Inputs.data, data)
input_sum.assert_called_with(int(StateInfo.format_number(len(data))))
output = self.get_output(self.widget.Outputs.data)
output_sum.assert_called_with(int(StateInfo.format_number(len(output))))

input_sum.reset_mock()
output_sum.reset_mock()
self.send_signal(self.widget.Inputs.data, None)
input_sum.assert_called_once()
self.assertEqual(input_sum.call_args[0][0].brief, "")
output_sum.assert_called_once()
self.assertEqual(output_sum.call_args[0][0].brief, "")