From 27c11e41c2bfda042d8ef999f790fe9e85103347 Mon Sep 17 00:00:00 2001 From: Aleksandra Date: Fri, 6 Mar 2020 10:31:23 +0100 Subject: [PATCH] Data info displayed in the status bar --- Orange/widgets/data/owdatasampler.py | 11 ++++++--- .../widgets/data/tests/test_owdatasampler.py | 23 ++++++++++--------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Orange/widgets/data/owdatasampler.py b/Orange/widgets/data/owdatasampler.py index 74174d5417a..a012b0ed63b 100644 --- a/Orange/widgets/data/owdatasampler.py +++ b/Orange/widgets/data/owdatasampler.py @@ -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 @@ -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() @@ -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) diff --git a/Orange/widgets/data/tests/test_owdatasampler.py b/Orange/widgets/data/tests/test_owdatasampler.py index 2c4d290ee3a..53c016cbc00 100644 --- a/Orange/widgets/data/tests/test_owdatasampler.py +++ b/Orange/widgets/data/tests/test_owdatasampler.py @@ -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): @@ -38,7 +39,6 @@ def test_stratified_on_unbalanced_data(self): self.assertTrue(self.widget.Warning.could_not_stratify.is_shown()) def test_bootstrap(self): - output_sum = self.widget.info.set_output_summary = Mock() self.select_sampling_type(self.widget.Bootstrap) self.send_signal("Data", self.iris) @@ -59,8 +59,6 @@ def test_bootstrap(self): # high probability (1-(1/150*2/150*...*150/150) ~= 1-2e-64) self.assertGreater(len(in_sample), 0) self.assertGreater(len(in_remaining), 0) - #Check if status bar shows correct number of output data - output_sum.assert_called_with(str(len(sample))) def select_sampling_type(self, sampling_type): buttons = self.widget.controls.sampling_type.group.buttons() @@ -68,11 +66,9 @@ def select_sampling_type(self, sampling_type): def test_no_intersection_in_outputs(self): """ Check whether outputs intersect and whether length of outputs sums - to length of original data and - if status bar displays correct output for each sampling type""" + to length of original data""" self.send_signal("Data", self.iris) w = self.widget - output_sum = self.widget.info.set_output_summary = Mock() sampling_types = [w.FixedProportion, w.FixedSize, w.CrossValidation] for replicable in [True, False]: @@ -87,7 +83,6 @@ def test_no_intersection_in_outputs(self): other = self.get_output("Remaining Data") self.assertEqual(len(self.iris), len(sample) + len(other)) self.assertNoIntersection(sample, other) - output_sum.assert_called_with(str(len(sample))) def test_bigger_size_with_replacement(self): """Allow bigger output without replacement.""" @@ -126,17 +121,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.