diff --git a/Orange/widgets/data/owgroupby.py b/Orange/widgets/data/owgroupby.py index 07821aec2d6..ad160b55f37 100644 --- a/Orange/widgets/data/owgroupby.py +++ b/Orange/widgets/data/owgroupby.py @@ -443,9 +443,14 @@ def set_data(self, data: Table) -> None: if data else {} ) + default_aggregations = self.aggregations.copy() self.openContext(self.data) + # restore aggregations + self.aggregations.update({k: v for k, v in default_aggregations.items() + if k not in self.aggregations}) + # update selections in widgets and re-plot self.agg_table_model.set_domain(data.domain if data else None) self._set_gb_selection() diff --git a/Orange/widgets/data/tests/test_owgroupby.py b/Orange/widgets/data/tests/test_owgroupby.py index 4356622aca2..b2c6c2c6de2 100644 --- a/Orange/widgets/data/tests/test_owgroupby.py +++ b/Orange/widgets/data/tests/test_owgroupby.py @@ -20,7 +20,7 @@ from Orange.widgets.tests.base import WidgetTest -class TestOWGropBy(WidgetTest): +class TestOWGroupBy(WidgetTest): def setUp(self) -> None: self.widget = self.create_widget(OWGroupBy) self.iris = Table("iris") @@ -46,6 +46,14 @@ def test_data(self): self.send_signal(self.widget.Inputs.data, None) self.assertIsNone(self.get_output(self.widget.Outputs.data)) + def test_data_domain_changed(self): + self.send_signal(self.widget.Inputs.data, self.iris[:, -2:]) + self.assert_aggregations_equal(["Mean", "Concatenate"]) + + self.send_signal(self.widget.Inputs.data, self.iris[:, -3:]) + self.assert_aggregations_equal(["Mean", "Mean", "Concatenate"]) + self.select_table_rows(self.widget.agg_table_view, [0]) + @staticmethod def _set_selection(view: QListView, indices: List[int]): view.clearSelection()