Package logilab :: Package common :: Module table :: Class Table

[frames] | no frames]

# Class Table

source code

    object --+
             |
            Table

    Table defines a data table with column and row names.
    inv:
        len(self.data) <= len(self.row_names)
        forall(self.data, lambda x: len(x) <= len(self.col_names))

Instance Methods

__init__(self, default_value=0, col_names=None, row_names=None) x.__init__(...) initializes x; see help(type(x)) for signature | source code

__iter__(self) | source code

__eq__(self, other) | source code

__hash__(x) hash(x) | source code

__ne__(self, other) | source code

__len__(self) | source code

create_rows(self, row_names) Appends row_names to the list of existing rows... | source code

create_columns(self, col_names) Appends col_names to the list of existing columns... | source code

create_row(self, row_name=None) Creates a rowname to the row_names list... | source code

create_column(self, col_name) Creates a colname to the col_names list... | source code

sort_by_column_id(self, col_id, method='asc') Sorts the table (in-place) according to data stored in col_id... | source code

sort_by_column_index(self, col_index, method='asc') Sorts the table 'in-place' according to data stored in col_index | source code

groupby(self, colname, *others) builds indexes of data... | source code

select(self, colname, value) | source code

remove(self, colname, value) | source code

set_cell(self, row_index, col_index, data) sets value of cell 'row_indew', 'col_index' to data... | source code

set_cell_by_ids(self, row_id, col_id, data) sets value of cell mapped by row_id and col_id to data... | source code

set_row(self, row_index, row_data) sets the 'row_index' row... | source code

set_row_by_id(self, row_id, row_data) sets the 'row_id' column... | source code

append_row(self, row_data, row_name=None) Appends a row to the table... | source code

insert_row(self, index, row_data, row_name=None) Appends row_data before 'index' in the table. | source code

delete_row(self, index) Deletes the 'index' row in the table, and returns it. | source code

delete_row_by_id(self, row_id) Deletes the 'row_id' row in the table. | source code

set_column(self, col_index, col_data) sets the 'col_index' column... | source code

set_column_by_id(self, col_id, col_data) sets the 'col_id' column... | source code

append_column(self, col_data, col_name) Appends the 'col_index' column... | source code

insert_column(self, index, col_data, col_name) Appends col_data before 'index' in the table. | source code

delete_column(self, index) Deletes the 'index' column in the table, and returns it. | source code

delete_column_by_id(self, col_id) Deletes the 'col_id' col in the table. | source code

get_shape(self) Returns a tuple which represents the table's shape... | source code

shape(self) Returns a tuple which represents the table's shape... | source code

__getitem__(self, indices) provided for convenience | source code

get_cell_by_ids(self, row_id, col_id) Returns the element at [row_id][col_id]... | source code

get_row_by_id(self, row_id) Returns the 'row_id' row... | source code

get_column_by_id(self, col_id, distinct=False) Returns the 'col_id' col... | source code

get_columns(self) Returns all the columns in the table... | source code

get_column(self, col_index, distinct=False) get a column by index | source code

apply_stylesheet(self, stylesheet) Applies the stylesheet to this table... | source code

transpose(self) Keeps the self object intact, and returns the transposed (rotated) table. | source code

pprint(self) returns a string representing the table in a pretty printed 'text' format. | source code

__repr__(self) repr(x) | source code

as_text(self) | source code

Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self, default_value=0, col_names=None, row_names=None)
(Constructor)

source code

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
  (inherited documentation)

### __hash__(x)
(Hashing function)

source code

    hash(x)

Overrides: object.__hash__

### create_rows(self, row_names)

source code

    Appends row_names to the list of existing rows

### create_columns(self, col_names)

source code

    Appends col_names to the list of existing columns

### create_row(self, row_name=None)

source code

    Creates a rowname to the row_names list

### create_column(self, col_name)

source code

    Creates a colname to the col_names list

### sort_by_column_id(self, col_id, method='asc')

source code

    Sorts the table (in-place) according to data stored in col_id

### sort_by_column_index(self, col_index, method='asc')

source code

    Sorts the table 'in-place' according to data stored in col_index

    method should be in ('asc', 'desc')

### groupby(self, colname, *others)

source code

    builds indexes of data
    :returns: nested dictionaries pointing to actual rows

### set_cell(self, row_index, col_index, data)

source code

    sets value of cell 'row_indew', 'col_index' to data

### set_cell_by_ids(self, row_id, col_id, data)

source code

    sets value of cell mapped by row_id and col_id to data
    Raises a KeyError if row_id or col_id are not found in the table

### set_row(self, row_index, row_data)

source code

    sets the 'row_index' row
    pre:
        type(row_data) == types.ListType
        len(row_data) == len(self.col_names)

### set_row_by_id(self, row_id, row_data)

source code

    sets the 'row_id' column
    pre:
        type(row_data) == types.ListType
        len(row_data) == len(self.row_names)
    Raises a KeyError if row_id is not found

### append_row(self, row_data, row_name=None)

source code

    Appends a row to the table
    pre:
        type(row_data) == types.ListType
        len(row_data) == len(self.col_names)

### insert_row(self, index, row_data, row_name=None)

source code

    Appends row_data before 'index' in the table. To make 'insert'
    behave like 'list.insert', inserting in an out of range index will
    insert row_data to the end of the list
    pre:
        type(row_data) == types.ListType
        len(row_data) == len(self.col_names)

### delete_row(self, index)

source code

    Deletes the 'index' row in the table, and returns it.
    Raises an IndexError if index is out of range

### delete_row_by_id(self, row_id)

source code

    Deletes the 'row_id' row in the table.
    Raises a KeyError if row_id was not found.

### set_column(self, col_index, col_data)

source code

    sets the 'col_index' column
    pre:
        type(col_data) == types.ListType
        len(col_data) == len(self.row_names)

### set_column_by_id(self, col_id, col_data)

source code

    sets the 'col_id' column
    pre:
        type(col_data) == types.ListType
        len(col_data) == len(self.col_names)
    Raises a KeyError if col_id is not found

### append_column(self, col_data, col_name)

source code

    Appends the 'col_index' column
    pre:
        type(col_data) == types.ListType
        len(col_data) == len(self.row_names)

### insert_column(self, index, col_data, col_name)

source code

    Appends col_data before 'index' in the table. To make 'insert'
    behave like 'list.insert', inserting in an out of range index will
    insert col_data to the end of the list
    pre:
        type(col_data) == types.ListType
        len(col_data) == len(self.row_names)

### delete_column(self, index)

source code

    Deletes the 'index' column in the table, and returns it.
    Raises an IndexError if index is out of range

### delete_column_by_id(self, col_id)

source code

    Deletes the 'col_id' col in the table.
    Raises a KeyError if col_id was not found.

### get_shape(self)

source code

    Returns a tuple which represents the table's shape

### shape(self)

source code

    Returns a tuple which represents the table's shape

### get_cell_by_ids(self, row_id, col_id)

source code

    Returns the element at [row_id][col_id]

### get_row_by_id(self, row_id)

source code

    Returns the 'row_id' row

### get_column_by_id(self, col_id, distinct=False)

source code

    Returns the 'col_id' col

### get_columns(self)

source code

    Returns all the columns in the table

### apply_stylesheet(self, stylesheet)

source code

    Applies the stylesheet to this table

### __repr__(self)
(Representation operator)

source code

repr(x)

Overrides: object.__repr__
  (inherited documentation)