Beispiel #1
0
    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")])
Beispiel #2
0
    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')])
Beispiel #3
0
    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')])
Beispiel #4
0
    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'])
Beispiel #5
0
    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])
Beispiel #6
0
    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)])
Beispiel #7
0
    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)])
Beispiel #8
0
    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])
Beispiel #9
0
    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])
Beispiel #10
0
    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)
Beispiel #11
0
    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])
Beispiel #12
0
    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))
Beispiel #13
0
    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))
Beispiel #14
0
    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)
Beispiel #15
0
    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))
Beispiel #16
0
    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))
Beispiel #17
0
    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))
Beispiel #18
0
    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))
Beispiel #19
0
    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)
        ])
Beispiel #20
0
    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])
Beispiel #21
0
    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)
        ])
Beispiel #22
0
    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))
Beispiel #23
0
    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)
        ])
Beispiel #24
0
    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)
Beispiel #25
0
    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"])
Beispiel #26
0
    def test_aggregate_sum_invalid(self):
        tableset = TableSet(self.tables.values(), self.tables.keys())

        with self.assertRaises(DataTypeError):
            tableset.aggregate([('letter', Sum(), 'letter_sum')])
Beispiel #27
0
    def test_aggregate_sum_invalid(self):
        tableset = TableSet(self.tables)

        with self.assertRaises(UnsupportedAggregationError):
            tableset.aggregate([('letter', Sum(), 'letter_sum')])
Beispiel #28
0
    def test_aggregate_sum_invalid(self):
        tableset = TableSet(self.tables.values(), self.tables.keys())

        with self.assertRaises(DataTypeError):
            tableset.aggregate([('letter_sum', Sum('letter'))])
Beispiel #29
0
    def test_aggregate_sum_invalid(self):
        tableset = TableSet(self.tables)

        with self.assertRaises(UnsupportedAggregationError):
            tableset.aggregate([('letter', Sum(), 'letter_sum')])