Skip to content

Commit

Permalink
Merge pull request #4473 from aturanjanin/owrank
Browse files Browse the repository at this point in the history
[ENH] OWRank: Data info displayed in the status bar
  • Loading branch information
VesnaT authored Mar 6, 2020
2 parents 15595f1 + 83fd5ae commit 1069c4f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Orange/widgets/data/owrank.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from Orange.widgets.utils.itemmodels import PyTableModel
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, AttributeList
)
Expand Down Expand Up @@ -293,6 +294,9 @@ def button(text, buttonid, toolTip=None):

gui.auto_send(selMethBox, self, "auto_apply", box=False)

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

self.resize(690, 500)

def switchProblemType(self, index):
Expand Down Expand Up @@ -325,6 +329,8 @@ def set_data(self, data):
self.switchProblemType(ProblemType.CLASSIFICATION)
if self.data is not None:
domain = self.data.domain
self.info.set_input_summary(len(self.data),
format_summary_details(self.data))

if domain.has_discrete_class:
problem_type = ProblemType.CLASSIFICATION
Expand All @@ -346,6 +352,8 @@ def set_data(self, data):
max((a.name for a in domain.attributes), key=len))

self.selectionMethod = OWRank.SelectNBest
else:
self.info.set_input_summary(self.info.NoInput)

self.openContext(data)
self.selectButtons.button(self.selectionMethod).setChecked(True)
Expand Down Expand Up @@ -536,13 +544,16 @@ def commit(self):
self.Outputs.reduced_data.send(None)
self.Outputs.features.send(None)
self.out_domain_desc = None
self.info.set_output_summary(self.info.NoOutput)
else:
reduced_domain = Domain(
selected_attrs, self.data.domain.class_var, self.data.domain.metas)
data = self.data.transform(reduced_domain)
self.Outputs.reduced_data.send(data)
self.Outputs.features.send(AttributeList(selected_attrs))
self.out_domain_desc = report.describe_domain(data.domain)
self.info.set_output_summary(len(data),
format_summary_details(data))

def create_scores_table(self, labels):
model_list = self.ranksModel.tolist()
Expand Down
24 changes: 23 additions & 1 deletion Orange/widgets/data/tests/test_owrank.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=unsubscriptable-object
import warnings
import unittest
from unittest.mock import patch
from unittest.mock import patch, Mock

import numpy as np
from sklearn.exceptions import ConvergenceWarning
Expand All @@ -17,6 +18,7 @@
from Orange.widgets.data.owrank import OWRank, ProblemType, CLS_SCORES, REG_SCORES
from Orange.widgets.tests.base import WidgetTest, datasets
from Orange.widgets.widget import AttributeList
from Orange.widgets.utils.state_summary import format_summary_details


class TestOWRank(WidgetTest):
Expand Down Expand Up @@ -405,6 +407,26 @@ def test_selected_rows(self):

self.assertEqual(len(output), len(self.iris))

def test_summary(self):
"""Check if the status bar is updated when data is received"""
data = self.iris
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.reduced_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, "")


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

0 comments on commit 1069c4f

Please sign in to comment.