File: where.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 (27 lines) | stat: -rw-r--r-- 692 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
def where(self, test):
    """
    Create a new :class:`.Table` with only those rows that pass a test.

    :param test:
        A function that takes a :class:`.Row` and returns :code:`True` if
        it should be included in the new :class:`.Table`.
    :type test:
        :class:`function`
    :returns:
        A new :class:`.Table`.
    """
    rows = []

    if self._row_names is not None:
        row_names = []
    else:
        row_names = None

    for i, row in enumerate(self._rows):
        if test(row):
            rows.append(row)

            if row_names is not None:
                row_names.append(self._row_names[i])

    return self._fork(rows, row_names=row_names)