Beispiel #1
0
    def setUp(self):
        self.table1 = (
            ('a', 1),
            ('a', 3),
            ('b', 2)
        )

        self.table2 = (
            ('b', 0),
            ('a', 2),
            ('c', 5)
        )

        self.table3 = (
            ('a', 1),
            ('a', 2),
            ('c', 3)
        )

        self.text_type = TextType()
        self.number_type = NumberType()

        self.columns = (
            ('letter', self.text_type),
            ('number', self.number_type)
        )

        self.tables = OrderedDict([
            ('table1', Table(self.table1, self.columns)),
            ('table2', Table(self.table2, self.columns)),
            ('table3', Table(self.table3, self.columns))
        ])
Beispiel #2
0
    def setUp(self):
        self.rows = ((1, 4, 'a'), (2, 3, 'b'), (None, 2, 'c'))

        self.number_type = NumberType()
        self.text_type = TextType()

        self.columns = (('one', self.number_type), ('two', self.number_type),
                        ('three', self.text_type))
Beispiel #3
0
    def setUp(self):
        self.rows = (('a', 2, 3, 4), (None, 3, 5, None), ('a', 2, 4, None),
                     ('b', 3, 4, None))

        self.number_type = NumberType()
        self.text_type = TextType()

        self.columns = (('one', self.text_type), ('two', self.number_type),
                        ('three', self.number_type), ('four',
                                                      self.number_type))
Beispiel #4
0
    def setUp(self):
        self.rows = ((Decimal('1.1'), Decimal('2.19'),
                      'a'), (Decimal('2.7'), Decimal('3.42'), 'b'),
                     (None, Decimal('4.1'), 'c'), (Decimal('2.7'),
                                                   Decimal('3.42'), 'c'))

        self.number_type = NumberType()
        self.text_type = TextType()

        self.columns = (('one', self.number_type), ('two', self.number_type),
                        ('three', self.text_type))

        self.table = Table(self.rows, self.columns)
Beispiel #5
0
    def setUp(self):
        self.left_rows = ((1, 4, 'a'), (2, 3, 'b'), (None, 2, 'c'))

        self.right_rows = ((1, 4, 'a'), (2, 3, 'b'), (None, 2, 'c'))

        self.number_type = NumberType()
        self.text_type = TextType()

        self.left_columns = (('one', self.number_type),
                             ('two', self.number_type), ('three',
                                                         self.text_type))

        self.right_columns = (('four', self.number_type),
                              ('five', self.number_type), ('six',
                                                           self.text_type))

        self.left = Table(self.left_rows, self.left_columns)
        self.right = Table(self.right_rows, self.right_columns)
Beispiel #6
0
    def aggregate(self, aggregations=[]):
        """
        Aggregate data from the tables in this set by performing some
        set of column operations on the groups and coalescing the results into
        a new :class:`.Table`.

        :class:`group` and :class:`count` columns will always be included as at
        the beginning of the output table, before the aggregated columns.

        :code:`aggregations` must be a list of tuples, where each has three
        parts: a :code:`column_name`, a :class:`.Aggregation` instance and a
        :code:`new_column_name`.

        :param aggregations: An list of triples in the format
            :code:`(column_name, aggregator, new_column_name)`.
        :returns: A new :class:`.Table`.
        """
        output = []

        column_types = [TextType(), NumberType()]
        column_names = ['group', 'count']

        for column_name, aggregator, new_column_name in aggregations:
            c = self._first_table.columns[column_name]

            column_types.append(aggregator.get_aggregate_column_type(c))
            column_names.append(new_column_name)

        for name, table in self._tables.items():
            new_row = [name, len(table.rows)]

            for column_name, aggregator, new_column_name in aggregations:
                c = table.columns[column_name]

                new_row.append(c.aggregate(aggregator))

            output.append(tuple(new_row))

        return self._first_table._fork(output, zip(column_names, column_types))