def test_pivot_time_val_var(self): domain = Domain([Dv("d1", ("a", "b")), Dv("d2", ("c", "d")), Tv("t1", have_date=1)]) X = np.array([[0, 1, 1e9], [0, 0, 1e8], [1, 0, 2e8], [1, 1, np.nan]]) table = Table(domain, X) # Min pivot = Pivot(table, [Pivot.Min], domain[0], domain[1], domain[2]) atts = (domain[0], Dv("Aggregate", ["Min"]), Tv("c", have_date=1), Tv("d", have_date=1)) X = np.array([[0, 0, 1e8, 1e9], [1, 0, 2e8, np.nan]]) self.assert_table_equal(pivot.pivot_table, Table(Domain(atts), X)) # Min, Max pivot = Pivot(table, [Pivot.Min, Pivot.Max], domain[0], domain[1], domain[2]) atts = (domain[0], Dv("Aggregate", ["Min", "Max"]), Tv("c", have_date=1), Tv("d", have_date=1)) X = np.array([[0, 0, 1e8, 1e9], [0, 1, 1e8, 1e9], [1, 0, 2e8, np.nan], [1, 1, 2e8, np.nan]]) self.assert_table_equal(pivot.pivot_table, Table(Domain(atts), X)) # Count defined, Sum pivot = Pivot(table, [Pivot.Count_defined, Pivot.Sum], domain[0], domain[1], domain[2]) atts = (domain[0], Dv("Aggregate", ["Count defined", "Sum"]), Cv("c"), Cv("d")) X = np.array([[0, 0, 1, 1], [0, 1, 1e8, 1e9], [1, 0, 1, 0], [1, 1, 2e8, 0]]) self.assert_table_equal(pivot.pivot_table, Table(Domain(atts), X)) # Count defined, Max pivot = Pivot(table, [Pivot.Count_defined, Pivot.Max], domain[0], domain[1], domain[2]) atts = (domain[0], Dv("Aggregate", ["Count defined", "Max"]), Dv("c", ["1.0", "1973-03-03", "1976-05-03"]), Dv("d", ["0.0", "1.0", "2001-09-09"])) X = np.array([[0, 0, 0, 1], [0, 1, 1, 2], [1, 0, 0, 0], [1, 1, 2, np.nan]]) self.assert_table_equal(pivot.pivot_table, Table(Domain(atts), X))
def test_output_grouped_data_time_var(self): domain = Domain([Dv("d1", ("a", "b")), Tv("t1", have_date=1)]) X = np.array([[0, 1e9], [0, 1e8], [1, 2e8], [1, np.nan]]) data = Table(domain, X) self.send_signal(self.widget.Inputs.data, data) self.agg_checkboxes[Pivot.Functions.Mean.value].click() grouped = self.get_output(self.widget.Outputs.grouped_data) str_grouped = "[[a, 2, 1987-06-06],\n [b, 2, 1976-05-03]]" self.assertEqual(str(grouped), str_grouped)
def test_group_table_time_var(self): domain = Domain([Dv("d1", ("a", "b")), Tv("t1", have_date=1)]) X = np.array([[0, 1e9], [0, 1e8], [1, 2e8], [1, np.nan]]) table = Table(domain, X) pivot = Pivot(table, Pivot.Functions, domain[0], val_var=domain[1]) str_grouped = \ "[[a, 2, 2, a, 2, 1.1e+09, 1987-06-06, 1973-03-03, " \ "2001-09-09, 1973-03-03, 1987-06-06, 2.025e+17],\n " \ "[b, 2, 2, b, 1, 2e+08, 1976-05-03, 1976-05-03, " \ "1976-05-03, 1976-05-03, 1976-05-03, 0]]" self.assertEqual(str(pivot.group_table), str_grouped)