File: select.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 (25 lines) | stat: -rw-r--r-- 642 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
from agate import utils
from agate.rows import Row


def select(self, key):
    """
    Create a new table with only the specified columns.

    :param key:
        Either the name of a single column to include or a sequence of such
        names.
    :returns:
        A new :class:`.Table`.
    """
    if not utils.issequence(key):
        key = [key]

    indexes = tuple(self._column_names.index(k) for k in key)
    column_types = tuple(self._column_types[i] for i in indexes)
    new_rows = []

    for row in self._rows:
        new_rows.append(Row((row[i] for i in indexes), key))

    return self._fork(new_rows, key, column_types)