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 4462394 commit 9a984b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
11 changes: 8 additions & 3 deletions Orange/widgets/data/owdatasampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from Orange.data import Table
from Orange.data.sql.table import SqlTable
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.widget import Msg, OWWidget, Input, Output
from Orange.util import Reprable

Expand Down Expand Up @@ -179,14 +180,14 @@ def set_data(self, dataset):
self.cb_seed.setVisible(not sql)
self.cb_stratify.setVisible(not sql)
self.cb_sql_dl.setVisible(sql)
self.info.set_input_summary(str(len(dataset)))
self.info.set_input_summary(len(dataset),
format_summary_details(dataset))

if not sql:
self._update_sample_max_size()
self.updateindices()
else:
self.info.set_input_summary(self.info.NoInput)
self.info.set_output_summary(self.info.NoInput)
self.indices = None
self.clear_messages()
self.commit()
Expand Down Expand Up @@ -224,12 +225,16 @@ def commit(self):
remaining, sample = self.indices
elif self.sampling_type == self.CrossValidation:
remaining, sample = self.indices[self.selectedFold - 1]
self.info.set_output_summary(str(len(sample)))

sample = self.data[sample]
other = self.data[remaining]
self.sampled_instances = len(sample)
self.remaining_instances = len(other)

summary = len(sample) if sample else self.info.NoOutput
details = format_summary_details(sample) if sample else ""
self.info.set_output_summary(summary, details)

self.Outputs.data_sample.send(sample)
self.Outputs.remaining_data.send(other)

Expand Down
15 changes: 11 additions & 4 deletions Orange/widgets/data/tests/test_owdatasampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from Orange.data import Table
from Orange.widgets.data.owdatasampler import OWDataSampler
from Orange.widgets.tests.base import WidgetTest
from Orange.widgets.utils.state_summary import format_summary_details


class TestOWDataSampler(WidgetTest):
Expand Down Expand Up @@ -126,17 +127,23 @@ def test_shuffling(self):

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

input_sum.reset_mock()
self.send_signal(self.widget.Inputs.data, data[:])
input_sum.assert_called_with("150")
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_sample)
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, "")

def set_fixed_sample_size(self, sample_size, with_replacement=False):
"""Set fixed sample size and return the number of gui spin.
Expand Down

0 comments on commit 9a984b7

Please sign in to comment.