Skip to content

Commit

Permalink
Merge pull request #5823 from VesnaT/groupby_restore_agg
Browse files Browse the repository at this point in the history
[FIX] Group by: Restore aggregations if removed due to open context
  • Loading branch information
janezd authored Feb 4, 2022
2 parents da56001 + 9212a76 commit 3516fc3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Orange/widgets/data/owgroupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 9 additions & 1 deletion Orange/widgets/data/tests/test_owgroupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()
Expand Down

0 comments on commit 3516fc3

Please sign in to comment.