Skip to content

Commit

Permalink
OWSelectByDataIndex: data info displayed in the status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
aturanjanin committed Apr 2, 2020
1 parent e0f241b commit 92a47c7
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Orange/widgets/data/owselectbydataindex.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import numpy as np

from AnyQt.QtCore import Qt

from Orange.data import Table
from Orange.widgets import widget, gui
from Orange.widgets.utils import itemmodels
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, \
format_multiple_summaries
from Orange.widgets.widget import Input, Output
from Orange.widgets.utils.annotated_data import (create_annotated_table)

Expand Down Expand Up @@ -49,6 +53,9 @@ def __init__(self):
self.infoBoxExtraData = gui.label(
box, self, self.data_info_text(None), box="Data Subset")

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

@Inputs.data
@check_sql_input
def set_data(self, data):
Expand All @@ -62,6 +69,19 @@ def set_data_subset(self, data):
self.infoBoxExtraData.setText(self.data_info_text(data))

def handleNewSignals(self):
summary, details, kwargs = self.info.NoInput, "", {}
if self.data or self.data_subset:
n_data = len(self.data) if self.data else 0
n_data_subset = len(self.data_subset) if self.data_subset else 0
summary = f"{self.info.format_number(n_data)}, " \
f"{self.info.format_number(n_data_subset)}"
kwargs = {"format": Qt.RichText}
details = format_multiple_summaries([
("Data", self.data),
("Data subset", self.data_subset)
])
self.info.set_input_summary(summary, details, **kwargs)

self._invalidate()

@staticmethod
Expand Down Expand Up @@ -89,6 +109,10 @@ def commit(self):
matching_output = self.data[row_sel]
non_matching_output = self.data[~row_sel]
annotated_output = create_annotated_table(self.data, row_sel)

summary = self.info.NoOutput if matching_output is None else len(matching_output)
details = "" if matching_output is None else format_summary_details(matching_output)
self.info.set_output_summary(summary, details)
self.Outputs.matching_data.send(matching_output)
self.Outputs.non_matching_data.send(non_matching_output)
self.Outputs.annotated_data.send(annotated_output)
Expand Down
46 changes: 46 additions & 0 deletions Orange/widgets/data/tests/test_owselectbydataindex.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# pylint: disable=protected-access
from Orange.data import Table, Domain
from Orange.widgets.data.owselectbydataindex import OWSelectByDataIndex
from Orange.widgets.tests.base import WidgetTest
from Orange.widgets.utils.annotated_data import ANNOTATED_DATA_FEATURE_NAME
from Orange.widgets.utils.state_summary import format_summary_details, \
format_multiple_summaries


class TestOWSelectSubset(WidgetTest):
Expand Down Expand Up @@ -43,3 +46,46 @@ def test_subset_nosubset(self):
self.assertTrue(self.widget.Warning.instances_not_matching.is_shown())
self.assertEqual([], list(matching))
self.assertEqual(list(data), list(non_matching))

def test_summary(self):
"""Check if the status bar is updated when data is received"""
data = Table("iris")
info = self.widget.info
NoInput, NoOutput = "No data on input", "No data on output"
self.assertEqual(info._StateInfo__input_summary.brief, "")
self.assertEqual(info._StateInfo__input_summary.details, NoInput)
self.assertEqual(info._StateInfo__output_summary.brief, "")
self.assertEqual(info._StateInfo__output_summary.details, NoOutput)

self.send_signal(self.widget.Inputs.data, data)
data_list = [("Data", data), ("Data subset", None)]
summary, details = f"{len(data)}, 0", format_multiple_summaries(data_list)
self.assertEqual(info._StateInfo__input_summary.brief, summary)
self.assertEqual(info._StateInfo__input_summary.details, details)
self.assertEqual(info._StateInfo__output_summary.brief, "0")

self.send_signal(self.widget.Inputs.data_subset, data)
data_list = [("Data", data), ("Data subset", data)]
summary = f"{len(data)}, {len(data)}"
details = format_multiple_summaries(data_list)
self.assertEqual(info._StateInfo__input_summary.brief, summary)
self.assertEqual(info._StateInfo__input_summary.details, details)
output = self.get_output(self.widget.Outputs.matching_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, None)
data_list = [("Data", None), ("Data subset", data)]
summary, details = f"0, {len(data)}", format_multiple_summaries(
data_list)
self.assertEqual(info._StateInfo__input_summary.brief, summary)
self.assertEqual(info._StateInfo__input_summary.details, details)
self.assertEqual(info._StateInfo__output_summary.brief, "")
self.assertEqual(info._StateInfo__output_summary.details, NoOutput)

self.send_signal(self.widget.Inputs.data_subset, None)
self.assertEqual(info._StateInfo__input_summary.brief, "")
self.assertEqual(info._StateInfo__input_summary.details, NoInput)
self.assertEqual(info._StateInfo__output_summary.brief, "")
self.assertEqual(info._StateInfo__output_summary.details, NoOutput)

0 comments on commit 92a47c7

Please sign in to comment.