Skip to content

Commit 3d45af3

Browse files
authored
Merge pull request #3382 from pavlin-policar/featstats-outputs
[FIX] Feature Statistics: Update outputs on new data
2 parents 8690622 + 87bc4d6 commit 3d45af3

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

Orange/widgets/data/owfeaturestatistics.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,10 +763,14 @@ def _filter_table_variables(self):
763763

764764
@Inputs.data
765765
def set_data(self, data):
766+
# Clear outputs and reset widget state
766767
self.closeContext()
767768
self.selected_rows = []
768769
self.model.resetSorting()
770+
self.Outputs.reduced_data.send(None)
771+
self.Outputs.statistics.send(None)
769772

773+
# Setup widget state for new data and restore settings
770774
self.data = data
771775

772776
if data is not None:
@@ -785,6 +789,7 @@ def set_data(self, data):
785789
self.__color_var_changed()
786790

787791
self.set_info()
792+
self.commit()
788793

789794
def __restore_selection(self):
790795
"""Restore the selection on the table view from saved settings."""

Orange/widgets/data/tests/test_owfeaturestatistics.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,70 @@ def setUp(self):
276276
[continuous_full, continuous_missing],
277277
target=[rgb_full, rgb_missing], metas=[ints_full, ints_missing]
278278
)
279-
self.send_signal('Data', self.data)
279+
self.send_signal(self.widget.Inputs.data, self.data)
280280
self.select_rows = partial(select_rows, widget=self.widget)
281281

282+
def test_changing_data_updates_ouput(self):
283+
# Test behaviour of widget when auto commit is OFF
284+
self.widget.auto_commit = False
285+
286+
# We start of with some data and select some rows
287+
self.send_signal(self.widget.Inputs.data, self.data)
288+
self.select_rows([0])
289+
# By default, nothing should be sent since auto commit is off
290+
self.assertIsNone(self.get_output(self.widget.Outputs.reduced_data))
291+
self.assertIsNone(self.get_output(self.widget.Outputs.statistics))
292+
# When we commit, the data should be on the output
293+
self.widget.unconditional_commit()
294+
self.assertIsNotNone(self.get_output(self.widget.Outputs.reduced_data))
295+
self.assertIsNotNone(self.get_output(self.widget.Outputs.statistics))
296+
297+
# Send some new data
298+
iris = Table('iris')
299+
self.send_signal(self.widget.Inputs.data, iris)
300+
# By default, there should be nothing on the output
301+
self.assertIsNone(self.get_output(self.widget.Outputs.reduced_data))
302+
self.assertIsNone(self.get_output(self.widget.Outputs.statistics))
303+
# Nothing should change after commit, since we haven't selected any rows
304+
self.widget.unconditional_commit()
305+
self.assertIsNone(self.get_output(self.widget.Outputs.reduced_data))
306+
self.assertIsNone(self.get_output(self.widget.Outputs.statistics))
307+
308+
# Now let's switch back to the original data, where we selected row 0
309+
self.send_signal(self.widget.Inputs.data, self.data)
310+
# Again, since auto commit is off, nothing should be on the output
311+
self.assertIsNone(self.get_output(self.widget.Outputs.reduced_data))
312+
self.assertIsNone(self.get_output(self.widget.Outputs.statistics))
313+
# Since the row selection is saved into context settings, the appropriate
314+
# thing should be sent to output
315+
self.widget.unconditional_commit()
316+
self.assertIsNotNone(self.get_output(self.widget.Outputs.reduced_data))
317+
self.assertIsNotNone(self.get_output(self.widget.Outputs.statistics))
318+
319+
def test_changing_data_updates_output_with_autocommit(self):
320+
# Test behaviour of widget when auto commit is ON
321+
self.widget.auto_commit = True
322+
323+
# We start of with some data and select some rows
324+
self.send_signal(self.widget.Inputs.data, self.data)
325+
self.select_rows([0])
326+
# Selecting rows should send data to output
327+
self.assertIsNotNone(self.get_output(self.widget.Outputs.reduced_data))
328+
self.assertIsNotNone(self.get_output(self.widget.Outputs.statistics))
329+
330+
# Send some new data
331+
iris = Table('iris')
332+
self.send_signal(self.widget.Inputs.data, iris)
333+
# Don't select anything, so the outputs should be empty
334+
self.assertIsNone(self.get_output(self.widget.Outputs.reduced_data))
335+
self.assertIsNone(self.get_output(self.widget.Outputs.statistics))
336+
337+
# Now let's switch back to the original data, where we had selected row 0,
338+
# we expect that to be sent to output
339+
self.send_signal(self.widget.Inputs.data, self.data)
340+
self.assertIsNotNone(self.get_output(self.widget.Outputs.reduced_data))
341+
self.assertIsNotNone(self.get_output(self.widget.Outputs.statistics))
342+
282343
def test_sends_single_attribute_table_to_output(self):
283344
# Check if selecting a single attribute row
284345
self.select_rows([0])

0 commit comments

Comments
 (0)