From a073258a8bf3047a008c78b7dd6ba497369059e9 Mon Sep 17 00:00:00 2001 From: PrimozGodec Date: Fri, 9 Sep 2022 13:34:26 +0200 Subject: [PATCH] Group By - fix std and sum for TimeVariable --- Orange/widgets/data/owgroupby.py | 6 ++++-- Orange/widgets/data/tests/test_owgroupby.py | 14 +++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Orange/widgets/data/owgroupby.py b/Orange/widgets/data/owgroupby.py index c5f4916b9f1..e0cfd994592 100644 --- a/Orange/widgets/data/owgroupby.py +++ b/Orange/widgets/data/owgroupby.py @@ -63,9 +63,11 @@ def concatenate(x): lambda x: pd.Series.mode(x).get(0, nan), {ContinuousVariable, DiscreteVariable, TimeVariable} ), - "Standard deviation": Aggregation("std", {ContinuousVariable, TimeVariable}), + "Standard deviation": Aggregation( + lambda s: s.std(), {ContinuousVariable, TimeVariable} + ), "Variance": Aggregation("var", {ContinuousVariable, TimeVariable}), - "Sum": Aggregation("sum", {ContinuousVariable, TimeVariable}), + "Sum": Aggregation("sum", {ContinuousVariable}), "Concatenate": Aggregation( concatenate, {ContinuousVariable, DiscreteVariable, StringVariable, TimeVariable}, diff --git a/Orange/widgets/data/tests/test_owgroupby.py b/Orange/widgets/data/tests/test_owgroupby.py index 3ce1c13bb21..475acfd1462 100644 --- a/Orange/widgets/data/tests/test_owgroupby.py +++ b/Orange/widgets/data/tests/test_owgroupby.py @@ -690,13 +690,21 @@ def test_time_variable(self): # time variable as a group by variable self.send_signal(self.widget.Inputs.data, data) - self._set_selection(self.widget.gb_attrs_view, [1]) + self._set_selection(self.widget.gb_attrs_view, [3]) output = self.get_output(self.widget.Outputs.data) self.assertEqual(3, len(output)) # time variable as a grouped variable - self.send_signal(self.widget.Inputs.data, data) - self._set_selection(self.widget.gb_attrs_view, [5]) + attributes = [data.domain["c2"], data.domain["d2"]] + self.send_signal(self.widget.Inputs.data, data[:, attributes]) + self._set_selection(self.widget.gb_attrs_view, [1]) # d2 + # check all aggregations + self.assert_aggregations_equal(["Mean", "Mode"]) + self.select_table_rows(self.widget.agg_table_view, [0]) # c2 + for cb in self.widget.agg_checkboxes.values(): + if cb.text() != "Mean": + cb.click() + self.assert_aggregations_equal(["Mean, Median, Mode and 12 more", "Mode"]) output = self.get_output(self.widget.Outputs.data) self.assertEqual(2, len(output))