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 :returns: nested dictionaries pointing to actual rows
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 Raises a KeyError if row_id or col_id are not found in the table
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. Raises an IndexError if index is out of range
source code
 
delete_row_by_id(self, row_id)
Deletes the 'row_id' row in the table. Raises a KeyError if row_id was not found.
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. Raises an IndexError if index is out of range
source code
 
delete_column_by_id(self, col_id)
Deletes the 'col_id' col in the table. Raises a KeyError if col_id was not found.
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__

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')

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)

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)

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)