def test_aggregeate_bad_column(self): tableset = TableSet(self.tables.values(), self.tables.keys()) with self.assertRaises(KeyError): tableset.aggregate([("one", Sum(), "one_sum")]) with self.assertRaises(KeyError): tableset.aggregate([("bad", Sum(), "bad_sum")])
def test_aggregeate_bad_column(self): tableset = TableSet(self.tables) with self.assertRaises(ColumnDoesNotExistError): tableset.aggregate([('one', Sum(), 'one_sum')]) with self.assertRaises(ColumnDoesNotExistError): tableset.aggregate([('bad', Sum(), 'bad_sum')])
def test_aggregeate_bad_column(self): tableset = TableSet(self.tables.values(), self.tables.keys()) with self.assertRaises(KeyError): tableset.aggregate([('one', Sum(), 'one_sum')]) with self.assertRaises(KeyError): tableset.aggregate([('bad', Sum(), 'bad_sum')])
def test_aggregate_row_names(self): tableset = TableSet(self.tables.values(), self.tables.keys(), key_name='test') new_table = tableset.aggregate([ ('count', Count()) ]) self.assertRowNames(new_table, ['table1', 'table2', 'table3'])
def test_aggregate_key_name(self): tableset = TableSet(self.tables.values(), self.tables.keys(), key_name="test") new_table = tableset.aggregate([("count", Length())]) self.assertIsInstance(new_table, Table) self.assertColumnNames(new_table, ("test", "count")) self.assertColumnTypes(new_table, [Text, Number])
def test_aggregate_max_length(self): tableset = TableSet(self.tables.values(), self.tables.keys()) new_table = tableset.aggregate([("count", Length()), ("letter_max_length", MaxLength("letter"))]) self.assertIsInstance(new_table, Table) self.assertColumnNames(new_table, ("group", "count", "letter_max_length")) self.assertColumnTypes(new_table, [Text, Number, Number]) self.assertRows(new_table, [("table1", 3, 1), ("table2", 3, 1), ("table3", 3, 1)])
def test_aggregate_sum(self): tableset = TableSet(self.tables.values(), self.tables.keys()) new_table = tableset.aggregate([("count", Length()), ("number_sum", Sum("number"))]) self.assertIsInstance(new_table, Table) self.assertColumnNames(new_table, ("group", "count", "number_sum")) self.assertColumnTypes(new_table, [Text, Number, Number]) self.assertRows(new_table, [("table1", 3, 6), ("table2", 3, 7), ("table3", 3, 6)])
def test_aggregate_row_names(self): tableset = TableSet(self.tables.values(), self.tables.keys(), key_name="test") new_table = tableset.aggregate([("number", Length(), "count")]) self.assertSequenceEqual(new_table.row_names, ["table1", "table2", "table3"]) self.assertSequenceEqual(new_table.rows["table1"], ["table1", 3]) self.assertSequenceEqual(new_table.rows["table2"], ["table2", 3]) self.assertSequenceEqual(new_table.rows["table3"], ["table3", 3])
def test_aggregate_key_name(self): tableset = TableSet(self.tables.values(), self.tables.keys(), key_name='test') new_table = tableset.aggregate([ ('count', Count()) ]) self.assertIsInstance(new_table, Table) self.assertColumnNames(new_table, ('test', 'count')) self.assertColumnTypes(new_table, [Text, Number])
def test_aggregate_key_name(self): tableset = TableSet(self.tables.values(), self.tables.keys(), key_name="test") new_table = tableset.aggregate([("number", Length(), "count")]) self.assertIsInstance(new_table, Table) self.assertEqual(len(new_table.rows), 3) self.assertEqual(len(new_table.columns), 2) self.assertSequenceEqual(new_table._column_names, ("test", "count")) self.assertIsInstance(new_table._column_types[0], Text) self.assertIsInstance(new_table._column_types[1], Number)
def test_aggregate_row_names(self): tableset = TableSet(self.tables.values(), self.tables.keys(), key_name='test') new_table = tableset.aggregate([ ('number', Length(), 'count') ]) self.assertSequenceEqual(new_table.row_names, ['table1', 'table2', 'table3']) self.assertSequenceEqual(new_table.rows['table1'], ['table1', 3]) self.assertSequenceEqual(new_table.rows['table2'], ['table2', 3]) self.assertSequenceEqual(new_table.rows['table3'], ['table3', 3])
def test_aggregate_max_length(self): tableset = TableSet(self.tables.values(), self.tables.keys()) new_table = tableset.aggregate([("letter", Length(), "count"), ("letter", MaxLength(), "letter_max_length")]) self.assertIsInstance(new_table, Table) self.assertEqual(len(new_table.rows), 3) self.assertEqual(len(new_table.columns), 3) self.assertSequenceEqual(new_table._column_names, ("group", "count", "letter_max_length")) self.assertSequenceEqual(new_table.rows[0], ("table1", 3, 1)) self.assertSequenceEqual(new_table.rows[1], ("table2", 3, 1)) self.assertSequenceEqual(new_table.rows[2], ("table3", 3, 1))
def test_aggregate_min(self): tableset = TableSet(self.tables.values(), self.tables.keys()) new_table = tableset.aggregate([("number", Length(), "count"), ("number", Min(), "number_min")]) self.assertIsInstance(new_table, Table) self.assertEqual(len(new_table.rows), 3) self.assertEqual(len(new_table.columns), 3) self.assertSequenceEqual(new_table._column_names, ("group", "count", "number_min")) self.assertIsInstance(new_table.columns["number_min"].data_type, Number) self.assertSequenceEqual(new_table.rows[0], ("table1", 3, 1)) self.assertSequenceEqual(new_table.rows[1], ("table2", 3, 0)) self.assertSequenceEqual(new_table.rows[2], ("table3", 3, 1))
def test_aggregate_key_name(self): tableset = TableSet(self.tables, key_name='test') new_table = tableset.aggregate([ ('number', Length(), 'count') ]) self.assertIsInstance(new_table, Table) self.assertEqual(len(new_table.rows), 3) self.assertEqual(len(new_table.columns), 2) self.assertSequenceEqual(new_table._column_names, ('test', 'count')) self.assertIsInstance(new_table._column_types[0], Text) self.assertIsInstance(new_table._column_types[1], Number)
def test_aggregate_two_ops(self): tableset = TableSet(self.tables.values(), self.tables.keys()) new_table = tableset.aggregate( [("number", Length(), "count"), ("number", Sum(), "number_sum"), ("number", Mean(), "number_mean")] ) self.assertIsInstance(new_table, Table) self.assertEqual(len(new_table.rows), 3) self.assertEqual(len(new_table.columns), 4) self.assertSequenceEqual(new_table._column_names, ("group", "count", "number_sum", "number_mean")) self.assertSequenceEqual(new_table.rows[0], ("table1", 3, 6, 2)) self.assertSequenceEqual(new_table.rows[1], ("table2", 3, 7, Decimal(7) / 3)) self.assertSequenceEqual(new_table.rows[2], ("table3", 3, 6, 2))
def test_aggregate_sum(self): tableset = TableSet(self.tables) new_table = tableset.aggregate([ ('number', Sum(), 'number_sum') ]) self.assertIsInstance(new_table, Table) self.assertEqual(len(new_table.rows), 3) self.assertEqual(len(new_table.columns), 3) self.assertSequenceEqual(new_table._column_names, ('group', 'count', 'number_sum')) self.assertSequenceEqual(new_table.rows[0], ('table1', 3, 6)) self.assertSequenceEqual(new_table.rows[1], ('table2', 3, 7)) self.assertSequenceEqual(new_table.rows[2], ('table3', 3, 6))
def test_aggregate_max_length(self): tableset = TableSet(self.tables) new_table = tableset.aggregate([ ('letter', MaxLength(), 'letter_max_length') ]) self.assertIsInstance(new_table, Table) self.assertEqual(len(new_table.rows), 3) self.assertEqual(len(new_table.columns), 3) self.assertSequenceEqual(new_table._column_names, ('group', 'count', 'letter_max_length')) self.assertSequenceEqual(new_table.rows[0], ('table1', 3, 1)) self.assertSequenceEqual(new_table.rows[1], ('table2', 3, 1)) self.assertSequenceEqual(new_table.rows[2], ('table3', 3, 1))
def test_aggregate_min(self): tableset = TableSet(self.tables) new_table = tableset.aggregate([ ('number', Min(), 'number_min') ]) self.assertIsInstance(new_table, Table) self.assertEqual(len(new_table.rows), 3) self.assertEqual(len(new_table.columns), 3) self.assertSequenceEqual(new_table._column_names, ('group', 'count', 'number_min')) self.assertIsInstance(new_table.columns['number_min'], NumberColumn) self.assertSequenceEqual(new_table.rows[0], ('table1', 3, 1)) self.assertSequenceEqual(new_table.rows[1], ('table2', 3, 0)) self.assertSequenceEqual(new_table.rows[2], ('table3', 3, 1))
def test_aggregate_sum(self): tableset = TableSet(self.tables.values(), self.tables.keys()) new_table = tableset.aggregate([ ('count', Count()), ('number_sum', Sum('number')) ]) self.assertIsInstance(new_table, Table) self.assertColumnNames(new_table, ('group', 'count', 'number_sum')) self.assertColumnTypes(new_table, [Text, Number, Number]) self.assertRows(new_table, [ ('table1', 3, 6), ('table2', 3, 7), ('table3', 3, 6) ])
def test_aggregate_key_type(self): tables = OrderedDict([ (1, Table(self.table1, self.column_names, self.column_types)), (2, Table(self.table2, self.column_names, self.column_types)), (3, Table(self.table3, self.column_names, self.column_types)) ]) tableset = TableSet(tables.values(), tables.keys(), key_name='test', key_type=self.number_type) new_table = tableset.aggregate([ ('count', Count()) ]) self.assertIsInstance(new_table, Table) self.assertColumnNames(new_table, ('test', 'count')) self.assertColumnTypes(new_table, [Number, Number])
def test_aggregate_max_length(self): tableset = TableSet(self.tables.values(), self.tables.keys()) new_table = tableset.aggregate([ ('count', Count()), ('letter_max_length', MaxLength('letter')) ]) self.assertIsInstance(new_table, Table) self.assertColumnNames(new_table, ('group', 'count', 'letter_max_length')) self.assertColumnTypes(new_table, [Text, Number, Number]) self.assertRows(new_table, [ ('table1', 3, 1), ('table2', 3, 1), ('table3', 3, 1) ])
def test_aggregate_two_ops(self): tableset = TableSet(self.tables.values(), self.tables.keys()) new_table = tableset.aggregate([ ('number', Length(), 'count'), ('number', Sum(), 'number_sum'), ('number', Mean(), 'number_mean') ]) self.assertIsInstance(new_table, Table) self.assertEqual(len(new_table.rows), 3) self.assertEqual(len(new_table.columns), 4) self.assertSequenceEqual(new_table._column_names, ('group', 'count', 'number_sum', 'number_mean')) self.assertSequenceEqual(new_table.rows[0], ('table1', 3, 6, 2)) self.assertSequenceEqual(new_table.rows[1], ('table2', 3, 7, Decimal(7) / 3)) self.assertSequenceEqual(new_table.rows[2], ('table3', 3, 6, 2))
def test_aggregate_two_ops(self): tableset = TableSet(self.tables.values(), self.tables.keys()) new_table = tableset.aggregate([ ('count', Length()), ('number_sum', Sum('number')), ('number_mean', Mean('number')) ]) self.assertIsInstance(new_table, Table) self.assertColumnNames(new_table, ('group', 'count', 'number_sum', 'number_mean')) self.assertColumnTypes(new_table, [Text, Number, Number, Number]) self.assertRows(new_table, [ ('table1', 3, 6, 2), ('table2', 3, 7, Decimal(7) / 3), ('table3', 3, 6, 2) ])
def test_aggregate_key_type(self): tables = OrderedDict([ (1, Table(self.table1, self.column_names, self.column_types)), (2, Table(self.table2, self.column_names, self.column_types)), (3, Table(self.table3, self.column_names, self.column_types)) ]) tableset = TableSet(tables.values(), tables.keys(), key_name='test', key_type=self.number_type) new_table = tableset.aggregate([ ('number', Length(), 'count') ]) self.assertIsInstance(new_table, Table) self.assertEqual(len(new_table.rows), 3) self.assertEqual(len(new_table.columns), 2) self.assertSequenceEqual(new_table._column_names, ('test', 'count')) self.assertIsInstance(new_table._column_types[0], Number) self.assertIsInstance(new_table._column_types[1], Number)
def test_aggregate_row_names(self): tableset = TableSet(self.tables.values(), self.tables.keys(), key_name="test") new_table = tableset.aggregate([("count", Length())]) self.assertRowNames(new_table, ["table1", "table2", "table3"])
def test_aggregate_sum_invalid(self): tableset = TableSet(self.tables.values(), self.tables.keys()) with self.assertRaises(DataTypeError): tableset.aggregate([('letter', Sum(), 'letter_sum')])
def test_aggregate_sum_invalid(self): tableset = TableSet(self.tables) with self.assertRaises(UnsupportedAggregationError): tableset.aggregate([('letter', Sum(), 'letter_sum')])
def test_aggregate_sum_invalid(self): tableset = TableSet(self.tables.values(), self.tables.keys()) with self.assertRaises(DataTypeError): tableset.aggregate([('letter_sum', Sum('letter'))])
def test_aggregate_sum_invalid(self): tableset = TableSet(self.tables) with self.assertRaises(UnsupportedAggregationError): tableset.aggregate([('letter', Sum(), 'letter_sum')])