File: having.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-- 1,077 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
def having(self, aggregations, test):
    """
    Create a new :class:`.TableSet` with only those tables that pass a test.

    This works by applying a sequence of :class:`Aggregation` instances to
    each table. The resulting dictionary of properties is then passed to
    the :code:`test` function.

    This method does not modify the underlying tables in any way.

    :param aggregations:
        A list of tuples in the format :code:`(name, aggregation)`, where
        each :code:`aggregation` is an instance of :class:`.Aggregation`.
    :param test:
        A function that takes a dictionary of aggregated properties and returns
        :code:`True` if it should be included in the new :class:`.TableSet`.
    :type test:
        :class:`function`
    :returns:
        A new :class:`.TableSet`.
    """
    new_tables = []
    new_keys = []

    for key, table in self.items():
        props = table.aggregate(aggregations)

        if test(props):
            new_tables.append(table)
            new_keys.append(key)

    return self._fork(new_tables, new_keys)