File: aggregate.py

package info (click to toggle)
python-agate 1.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,996 kB
  • sloc: python: 8,512; makefile: 126
file content (32 lines) | stat: -rw-r--r-- 932 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from collections import OrderedDict

from agate import utils


def aggregate(self, aggregations):
    """
    Apply one or more :class:`.Aggregation` instances to this table.

    :param aggregations:
        A single :class:`.Aggregation` instance or a sequence of tuples in the
        format :code:`(name, aggregation)`, where each :code:`aggregation` is
        an instance of :class:`.Aggregation`.
    :returns:
        If the input was a single :class:`Aggregation` then a single result
        will be returned. If it was a sequence then an :class:`.OrderedDict` of
        results will be returned.
    """
    if utils.issequence(aggregations):
        results = OrderedDict()

        for name, agg in aggregations:
            agg.validate(self)

        for name, agg in aggregations:
            results[name] = agg.run(self)

        return results

    aggregations.validate(self)

    return aggregations.run(self)