Skip to content

Commit

Permalink
Data info displayed in the status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
aturanjanin committed Mar 6, 2020
1 parent 9541a29 commit 53bedef
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Orange/widgets/data/owimpute.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from Orange.widgets.utils import concurrent as qconcurrent
from Orange.widgets.utils.sql import check_sql_input
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.widget import OWWidget, Msg, Input, Output
from Orange.classification import SimpleTreeLearner

Expand Down Expand Up @@ -249,6 +250,9 @@ def __init__(self):
box.button.setFixedWidth(180)
box.layout().insertStretch(0)

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

def create_imputer(self, method, *args):
# type: (Method, ...) -> impute.BaseImputeMethod
if method == Method.Model:
Expand Down Expand Up @@ -300,6 +304,10 @@ def set_data(self, data):
# restore per variable imputation state
self._restore_state(self._variable_imputation_state)

summary = len(data) if data else self.info.NoInput
details = format_summary_details(data) if data else ""
self.info.set_input_summary(summary, details)

self.update_varview()
self.unconditional_commit()

Expand Down Expand Up @@ -346,6 +354,7 @@ def commit(self):

if not self.data or not self.varmodel.rowCount():
self.Outputs.data.send(self.data)
self.info.set_output_summary(self.info.NoOutput)
self.modified = False
return

Expand Down Expand Up @@ -452,6 +461,9 @@ def create_data(attributes, class_vars):

self.Outputs.data.send(data)
self.modified = False
summary = len(data) if data else self.info.NoOutput
details = format_summary_details(data) if data else ""
self.info.set_output_summary(summary, details)

@Slot(int, int)
def __progress_changed(self, n, d):
Expand Down
30 changes: 29 additions & 1 deletion Orange/widgets/data/tests/test_owimpute.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring,pointless-statement,blacklisted-name
# pylint: disable=missing-docstring,pointless-statement,blacklisted-name,unsubscriptable-object
from unittest.mock import Mock
import numpy as np

from AnyQt.QtCore import Qt, QItemSelection
Expand All @@ -11,6 +12,7 @@
from Orange.widgets.tests.base import WidgetTest
from Orange.widgets.tests.utils import simulate
from Orange.widgets.utils.itemmodels import select_row
from Orange.widgets.utils.state_summary import format_summary_details


class Foo(Learner):
Expand Down Expand Up @@ -181,3 +183,29 @@ def effective_method(var):
widget.value_combo.isEnabledTo(widget))
self.assertEqual(varbg.checkedId(), Method.Default)
self.assertEqual(widget.value_combo.currentIndex(), 1)

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

self.send_signal(self.widget.Inputs.data, data)
input_sum.assert_called_with(len(data), format_summary_details(data))
output = self.get_output(self.widget.Outputs.data)
output_sum.assert_called_with(len(output),
format_summary_details(output))

varbg = self.widget.variable_button_group
varbg.button(Method.AsValue).click()
output = self.get_output(self.widget.Outputs.data)
output_sum.assert_called_with(len(output),
format_summary_details(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, "")

0 comments on commit 53bedef

Please sign in to comment.