|
12 | 12 | from Orange.data import ( |
13 | 13 | Table, |
14 | 14 | table_to_frame, |
| 15 | + Domain, |
| 16 | + ContinuousVariable, |
15 | 17 | ) |
16 | 18 | from Orange.data.tests.test_aggregate import create_sample_data |
17 | 19 | from Orange.widgets.data.owgroupby import OWGroupBy |
@@ -689,6 +691,65 @@ def test_time_variable(self): |
689 | 691 | output = self.get_output(self.widget.Outputs.data) |
690 | 692 | self.assertEqual(2, len(output)) |
691 | 693 |
|
| 694 | + def test_only_nan_in_group(self): |
| 695 | + data = Table( |
| 696 | + Domain([ContinuousVariable("A"), ContinuousVariable("B")]), |
| 697 | + np.array([[1, np.nan], [2, 1], [1, np.nan], [2, 1]]), |
| 698 | + ) |
| 699 | + self.send_signal(self.widget.Inputs.data, data) |
| 700 | + |
| 701 | + # select feature A as group-by |
| 702 | + self._set_selection(self.widget.gb_attrs_view, [0]) |
| 703 | + # select all aggregations for feature B |
| 704 | + self.select_table_rows(self.widget.agg_table_view, [1]) |
| 705 | + for cb in self.widget.agg_checkboxes.values(): |
| 706 | + while not cb.isChecked(): |
| 707 | + cb.click() |
| 708 | + |
| 709 | + # unselect all aggregations for attr A |
| 710 | + self.select_table_rows(self.widget.agg_table_view, [0]) |
| 711 | + for cb in self.widget.agg_checkboxes.values(): |
| 712 | + while cb.isChecked(): |
| 713 | + cb.click() |
| 714 | + |
| 715 | + expected_columns = [ |
| 716 | + "B - Mean", |
| 717 | + "B - Median", |
| 718 | + "B - Mode", |
| 719 | + "B - Standard deviation", |
| 720 | + "B - Variance", |
| 721 | + "B - Sum", |
| 722 | + "B - Min. value", |
| 723 | + "B - Max. value", |
| 724 | + "B - Span", |
| 725 | + "B - First value", |
| 726 | + "B - Last value", |
| 727 | + "B - Random value", |
| 728 | + "B - Count defined", |
| 729 | + "B - Count", |
| 730 | + "B - Proportion defined", |
| 731 | + "B - Concatenate", |
| 732 | + "A", |
| 733 | + ] |
| 734 | + n = np.nan |
| 735 | + expected_df = pd.DataFrame( |
| 736 | + [ |
| 737 | + [n, n, n, n, n, 0, n, n, n, n, n, n, 0, 2, 0, "", 1], |
| 738 | + [1, 1, 1, 0, 0, 2, 1, 1, 0, 1, 1, 1, 2, 2, 1, "1.0 1.0", 2], |
| 739 | + ], |
| 740 | + columns=expected_columns, |
| 741 | + ) |
| 742 | + output_df = table_to_frame( |
| 743 | + self.get_output(self.widget.Outputs.data), include_metas=True |
| 744 | + ) |
| 745 | + pd.testing.assert_frame_equal( |
| 746 | + output_df, |
| 747 | + expected_df, |
| 748 | + check_dtype=False, |
| 749 | + check_column_type=False, |
| 750 | + check_categorical=False, |
| 751 | + ) |
| 752 | + |
692 | 753 |
|
693 | 754 | if __name__ == "__main__": |
694 | 755 | unittest.main() |
0 commit comments