Package picalo :: Package base :: Module Table :: Class Table
[show private | hide private]
[frames | no frames]

Class Table


The primary data structure used in Picalo modules. This is the first object a user should learn about since it's used everywhere. Tables are the input into most functions and are also the return records of most functions.

See the Picalo manual for more information on tables.
Method Summary
Table __init__(self, columns, data)
Creates a Picalo Table.
Table __add__(self, other)
Adds two tables together.
returns __copy__(self)
Returns a copy of this table.
  __delitem__(self, index)
Removes a record from the table.
  __eq__(self, other)
Returns whether this table is equal to another table (or list of lists).
Record or Column __getitem__(self, index)
Retrieves a record or a full column of the table.
  __getslice__(self, i, j)
Creates a new Table populated with records from i to j.
  __iadd__(self, other)
This is essentially the extend method.
iterator __iter__(self)
Returns an interator to the Records in this Table.
int __len__(self)
Return the number of records in the table.
str __repr__(self)
For debugging.
  __setitem__(self, index, record)
Replaces an existing Record with the given data.
  __sub__(self, other)
  _insert_column_(self, index, coldef, records, expression)
Internal method to inesrt a column once the Column object is created
Record append(self, *a, **k)
Inserts a new record at the end of this table.
Column append_calculated(self, name, expression)
Adds a new, calculated column with records given by expression.
Column append_calculated_static(self, name, column_type, expression)
Adds a new, calculated column with records given by expression.
Column append_column(self, name, column_type, records)
Adds a new column to the table, optionally setting records of the new cells.
  clear_filter(self)
Clears any active filter on this table, restoring the view to all records in the table
Column column(self, col)
Returns a single column of the table.
int column_count(self)
Retrieves the number of columns in a table.
  delete_column(self, column)
Removes a column from the table and discards the records.
int deref_column(self, col_name)
Dereferences the col name to its index (if it is a name).
  extend(self, table)
Appends the records in the given table to the end of this table.
  filter(self, expression)
Filters the table with the given expression.
list find(self, **pairs)
Finds the record indices with given key=record pairs.
list get_column_names(self)
Returns the column names of this table.
list get_columns(self)
Returns the column objects of this table.
  guess_types(self, num_records)
Inspects the first num_records in each column and automatically sets the type of each column.
  index(self, *col_names)
Returns an index on this table for the given column name(s).
returns insert(self, *a, **k)
Inserts a new record at the given index location.
Column insert_calculated(self, index, name, expression)
Inserts a new, calculated column with records given by expression at the given index location.
Column insert_calculated_static(self, index, name, column_type, expression)
Inserts a new, calculated column with records given by expression at the given index location.
Column insert_column(self, index, name, column_type, records)
Inserts a new column in the table at the given index location.
  is_changed(self)
Returns whether the table has been changed since loading
  is_filtered(self)
Returns True if this table has an active filter
bool is_readonly(self)
Returns whether this table is read only.
iterator iterator(self, respect_filter)
Returns an iterator to the Records in thistTable.
  move_column(self, column, new_index)
Moves a column to another location in the table.
  prettyprint(self, fp, center_columns, space_before, space_after, col_separator_char, row_separator_char, join_char, line_ending, none, respect_filter)
Pretty prints the table to the given fp.
Record record(self, index, respect_filter)
Retrieves the record at the given index.
int record_count(self, respect_filter)
Returns the number of records in this table.
  reorder_columns(self, columns)
Reorders the columns according to the given list.
  save(self, filename, respect_filter)
Saves this table in native Picalo format.
  save_csv(self, filename, line_ending, none, encoding, respect_filter)
Saves this table to a Comma Separated Values (CSV) text file.
  save_delimited(self, filename, delimiter, qualifier, line_ending, none, encoding, respect_filter)
Saves this table to a delimited text file.
  save_excel(self, filename, none, respect_filter)
Saves this table to a Microsoft Excel 97+ file.
  save_fixed(self, filename, line_ending, none, respect_filter)
Saves this table to a fixed width text file.
  save_tsv(self, filename, line_ending, none, encoding, respect_filter)
Saves this table to a Tab Separated Values (TSV) text file.
  save_xml(self, filename, line_ending, indent, compact, none, respect_filter)
Saves this table to an XML file using a pre-defined schema.
  set_changed(self, changed)
Sets whether the class has been changed since loading.
  set_format(self, column, format)
Sets the format of this column.
  set_name(self, column, name)
Changes the name of an existing column.
  set_readonly(self, readonly_flag)
Sets the read only status of this table.
  set_type(self, column, column_type, format, expression)
Sets the type of a column.
  sort(self, cmp, key, reverse)
Sorts this table with optional arguments.
Table structure(self)
Returns the structure of this table, including column names, input and output types, and general statistics.
  view(self)
Opens a spreadsheet-view of the table if Picalo is being run in GUI mode.
  _add_listener(self, listener)
Adds a listener to the table.
  _calculate_columns_map(self)
Calculates the columns map based upon the current columns.
  _check_page_size(self)
Checks the current page size to see if we need to split it into two pages
  _get_filtered_index(self, index)
Returns the filtered index of the given index, if a filter is in place.
  _invalidate_indexes(self)
Invalidates the indices already calculated on this table.
  _notify_listeners(self, level)
Notifies listeners that we've had a change
  _populate_record(self, rec, *a, **k)
Populates a record with data.
  _remove_listener(self, listener)
Removes a listener from the table.
  _save_dialect(self, filename, dialect, none, encoding, respect_filter)
Internal function to save according to a specific dialect (see the csv module docs)
  _set_cursor_datasource(self, cursor)
Sets the given cursor as the datasource for this table.
  _swap_page(self, new_pageindex)
Swaps the current page for a new one
  _swap_page_to_index(self, key)
Swaps the current page to the one including the given record
  _update_filter_index(self)
Updates the filter index.

Method Details

__init__(self, columns=3, data=[])
(Constructor)

Creates a Picalo Table. Tables are the single-most important item in Picalo. It should be the first place users look to understand how to use the program. See the manual for more information on how tables work.

The columns (field definitions) are required to be named and to have types. Fields are specified as a sequence of (name, type) pairs. The name can be any string starting with a letter and then any combination of letters and numbers. Column names must be unique. The type must be a type object, such as int, float, unicode, DateTime, etc. See below for examples.

The initial data for the table can be specified as a sequence of sequences, or a grid of data. See below for examples.

Example 1:
>>> # creates a table with two columns
>>> data = Table([
...  ( 'id',   int ),
...  ( 'name', unicode),
... ])
>>> data.structure().view()
+--------+------------------+------------+--------+
| Column |       Type       | Expression | Format |
+--------+------------------+------------+--------+
| id     | <type 'int'>     |    <N>     |  <N>   |
| name   | <type 'unicode'> |    <N>     |  <N>   |
+--------+------------------+------------+--------+
Example 2:
>>> # creates a table with two columns and initial data
>>> data = Table([
...   ( 'id',   int ),
...   ( 'name', unicode),
... ],[
...   [ 1, 'Danny'    ],
...   [ 2, 'Vijay'    ],
...   [ 3, 'Dongsong' ],
...   [ 4, 'Sally'    ],
... ])
>>> data.structure().view()
+--------+------------------+------------+--------+
| Column |       Type       | Expression | Format |
+--------+------------------+------------+--------+
| id     | <type 'int'>     |    <N>     |  <N>   |
| name   | <type 'unicode'> |    <N>     |  <N>   |
+--------+------------------+------------+--------+
Example 3:
>>> # creates a table with two columns (using shortcut notation)
>>> # since types are not specified, both columns are typed as unicode
>>> data = Table(['id', 'name'])
>>> data.structure().view()
+--------+------------------+------------+--------+
| Column |       Type       | Expression | Format |
+--------+------------------+------------+--------+
| id     | <type 'unicode'> |    <N>     |  <N>   |
| name   | <type 'unicode'> |    <N>     |  <N>   |
+--------+------------------+------------+--------+
Example 4:
>>> # creates a table with two columns (using another shortcut notation)
>>> data = Table(3)
>>> data.structure().view()
+--------+------------------+------------+--------+
| Column |       Type       | Expression | Format |
+--------+------------------+------------+--------+
| col000 | <type 'unicode'> |    <N>     |  <N>   |
| col001 | <type 'unicode'> |    <N>     |  <N>   |
| col002 | <type 'unicode'> |    <N>     |  <N>   |
+--------+------------------+------------+--------+
Parameters:
columns - A list of (name, type) pairs specifying the column names and their types
           (type=list)
data - The initial data for the table specified as another Picalo table or a list of lists.
           (type=Table/list)
Returns:
The new Picalo table.
           (type=Table)

__add__(self, other)
(Addition operator)

Adds two tables together. To be added together, two tables should have the same number of columns and be compatible with one another. The new table includes the records of the first table followed by the records of the second table. The column columns (and column calculations) of the first table are carried to the new table. The two source tables are not modified.

Stated differently, this method copies the first table and appends the second table's records to it.

Some users might expect this method to add individual cells together, similar to matrix addition. This is *not* the case. Instead, the new table includes all records from both tables.

Example:
>>> t1 = Table([('id', int)], [[1,1], [2,2]])
>>> t2 = Table([('id', int)], [[3,3], [4,4]])
>>> t3 = t1 + t2
>>> t3.view()
+--------+--------+
| col000 | col001 |
+--------+--------+
|      1 |      1 |
|      2 |      2 |
|      3 |      3 |
|      4 |      4 |
+--------+--------+
Parameters:
other - A Table to be added to this one.
           (type=Table)
Returns:
A new table with records from both tables
           (type=Table)

__copy__(self)

Returns a copy of this table. Use this method to make a full copy of all data.
Returns:
A new Table object with the columns and data of this Table.
           (type=returns)

__delitem__(self, index)
(Index deletion operator)

Removes a record from the table. The proper use to call this method is 'del table[i]' where i is the record number to remove. You can also specify columns to delete with 'del table["colname"]' where colname is the column name you want to delete.

__eq__(self, other)
(Equality operator)

Returns whether this table is equal to another table (or list of lists). Only the records of the table are compared -- not the column names or column definitions.

__getitem__(self, index)
(Indexing operator)

Retrieves a record or a full column of the table. If the given index is a column name, the column object is returned. If the given index is an integer, the given row object is returned.
Parameters:
index - The zero-based index of the record to pull OR the string name of the column to pull.
           (type=int or str)
Returns:
A Picalo Record object or Picalo Column object from this table
           (type=Record or Column)

__getslice__(self, i, j)
(Slicling operator)

Creates a new Table populated with records from i to j. This method is deprecated, but included since the super (list) still includes __getslice__.

__iadd__(self, other)

This is essentially the extend method. I included a += method directly to increase efficiency (so no intermediate table needs to be created)

__iter__(self)

Returns an interator to the Records in this Table. This is normally achieved through:
>>> for record in mytable:
>>>   # do something with each record object
Returns:
An iterator to this Table.
           (type=iterator)

__len__(self)
(Length operator)

Return the number of records in the table. The method respects any active filters on the table.
Returns:
The number of records in the table.
           (type=int)

__repr__(self)
(Representation operator)

For debugging. Use view() for a formatted printout.
Returns:
The number of rows and columns in the table.
           (type=str)

__setitem__(self, index, record)
(Index assignment operator)

Replaces an existing Record with the given data. Use = to set items.

Example:
>>> table = Table([('id', int)], [[1,2], [3,4]])
>>> table[1] = [5,6]
>>> table.view()
+--------+--------+
| col000 | col001 |
+--------+--------+
|      1 |      2 |
|      5 |      6 |
+--------+--------+
Parameters:
index - The index of the record where data will be replaced.
           (type=int)
record - A Record object, a list, or a Python sequence containing data for the
           (type=Record/list/tuple of columns for the record records.)

_insert_column_(self, index, coldef, records=None, expression=None)

Internal method to inesrt a column once the Column object is created

append(self, *a, **k)

Inserts a new record at the end of this table. This is the primary way to add new data to a table. If you need to insert a row in the middle of a table, use the insert() method.

Records can be added in any of the following ways:

Format 1:
  • newrec = mytable3.append()
  • newrec['ID'] = 4
  • newrec['Name'] = 'Homer'
  • newrec['Salary'] = 15000
Format 2:
  • mytable.append(4, 'Homer', 1500)
Format 3:
  • mytable3.append([4, 'Homer', 1500])
Format 4:
  • mytable3.append({'ID':5, 'Name':'Marge', 'Salary': 275000})
Format 5:
  • mytable3.append({0:5, 1:'Marge', 2: 275000})
Format 6:
  • mytable3.append(ID=5, Name='Krusty', Salary=50000)
You cannot mix formats in the same call.
Returns:
The new record object (that was appended to the end of the table)
           (type=Record)

append_calculated(self, name, expression)

Adds a new, calculated column with records given by expression. Calculated columns act as regular columns in all ways. Their records are 'active' meaning their records change when the result of the expression. In other words, they are recalculated each time they are used rather than being stored statically. This is similar to the way Excel functions always reflect the most updated data records.

Example:
>>> table = Table([('id', int)], [[1],[2],[4]])
>>> table.append_calculated('plusone', "col000+1")
>>> table.view()
+--------+---------+
| col000 | plusone |
+--------+---------+
|      1 |       2 |
|      2 |       3 |
|      4 |       5 |
+--------+---------+
Parameters:
name - The new column name
           (type=str)
expression - An expression that returns the record of the new field. As shown in the example, use rec to denote the current record being evaluated.
           (type=str)
Returns:
The new column object.
           (type=Column)

append_calculated_static(self, name, column_type, expression)

Adds a new, calculated column with records given by expression. The records are calculated immediately using expression, and then they are static. In other words, this method calculates a new, regular column. The records are not 'active' in the sense that append_calculated() columns are active. When this method returns, the new column is the same as any other, non-calculated column.

Example:
>>> table = Table([('id', int)], [[1],[2],[4]])
>>> table.append_calculated('plusone', int, "col000+1")
>>> table.view()
+--------+---------+
| col000 | plusone |
+--------+---------+
|      1 |       2 |
|      2 |       3 |
|      4 |       5 |
+--------+---------+
Parameters:
name - The new column name
           (type=str)
column_type - The type of the new column (str, Date, int, long, etc.)
           (type=type)
expression - An expression that returns the record of the new field. As shown in the example, use rec to denote the current record being evaluated.
           (type=str)
Returns:
The new column object.
           (type=Column)

append_column(self, name, column_type, records=None)

Adds a new column to the table, optionally setting records of the new cells.
Parameters:
name - The new column name
           (type=str)
column_type - The new column type (int, float, DateTime, unicode, str, etc)
           (type=type)
records - A list of records to place into the cells of the new column (if a full Table, the first column is used)
           (type=list, Column, or Table)
Returns:
The new column object.
           (type=Column)

clear_filter(self)

Clears any active filter on this table, restoring the view to all records in the table

column(self, col)

Returns a single column of the table. Column records can be read and modified but not deleted. This is a useful method when you want to work with a single column of a table.

The returned Column object is essentially a list of records and can be treated as such. Any function that takes a list can take a Column object.

This method is used often in analyses.
Parameters:
col - The column name to return
           (type=str)
Returns:
A Column object representing the specified column of the table.
           (type=Column)

column_count(self)

Retrieves the number of columns in a table. Note that since Picalo lists are zero-based, you access individual columns starting with 0.

So although column_count() may report 3 columns, you access them via table.column(0), table.column(1), and table.column(2).

However, using column names rather than direct indices is easier and more readable. table['colname'] returns the given column.
Returns:
The number columns in the table
           (type=int)

delete_column(self, column)

Removes a column from the table and discards the records. Remaining column indices are decremented to reflect the new table structure. Column names (columns) are not modified.

This action is permanent and cannot be undone.
Parameters:
column - The name or index of the column to be removed. If a list of columns, all of the columns are removed.
           (type=str or list)

deref_column(self, col_name)

Dereferences the col name to its index (if it is a name). For example, if the column name "id" is given, it returns the index of this column (such as 0, 1, 2, etc.).

The column can be specified as the column index, the column name, or even a negative index (from the last column backward).
Parameters:
col_name - The name of the column
           (type=str/int)
Returns:
The index of the column
           (type=int)

extend(self, table)

Appends the records in the given table to the end of this table. The two tables must have the same number of columns to be merged.

Example:
>>> mytable3.extend(mytable2)  # appends mytable2 to the end of mytable3
Parameters:
table - The records of the specified table will be added to this table.
           (type=Table)

filter(self, expression=None)

Filters the table with the given expression. Until the filter is either replaced or cleared, only the records matching the filter will be available in the table. All Picalo functions will see only this limited view of the table in their analyses. In other words, it is as if the filtered record is not in the table at all until the filter is removed.

Filters are transient. They do not save with the table and they do not carry over if you copy a table. They are simply temporary filters that you can use to restrict Picalo analyses to a few records.

Only one filter can be active at any time. Setting a new filter will replace the existing one.

In creating your expression, use the standard record['col'] notation to access individual records in the table.
Parameters:
expression - A valid Picalo expression that returns True or False. If the expression evaluates to Frue, the record is included in the filtered view. If False, the record is hidden from view.
           (type=str)

find(self, **pairs)

Finds the record indices with given key=record pairs. This method is not normally used directly -- use Simple.select_by_record instead.

This method is different than Simple.select_by_record in that it does not create a new table. Simple.select_by_record creates a new table consisting of copies of all matching records. In contrast, this method simply returns the record indices of the matching records.

This method *is* efficient and can be used often. It calculates indices as needed and should select very fast.

Example:
>>> table = Table([
...  ('col001', int),
...  ('col002', int),
...  ('col003', unicode),
... ],[
...  [5,6,'flo'], 
...  [3,2,'sally'], 
...  [4,6,'dan'], 
...  [4,7,'stu'], 
...  [4,7,'ben'],
...  [4,6,'benny'],
... ])
>>> results = table.find(col001=6, col000=4)
>>> results
[2, 5]
Parameters:
pairs - column=record pairings giving the key(s) to select on.
           (type=object)
Returns:
A list of indices that match the pairs.
           (type=list)

get_column_names(self)

Returns the column names of this table.
Returns:
A list of string names of columns
           (type=list)

get_columns(self)

Returns the column objects of this table. Columns are Column objects, which contain the column name, calculated expression (if any), type if set, etc.

Most users should call get_column_names() instead as it only returns the names of the columns. Only call this method if you need to access the internal column objects.
Returns:
A list of Column objects
           (type=list)

guess_types(self, num_records=-1)

Inspects the first num_records in each column and automatically sets the type of each column. This method is not perfect, but it is fairly robust. It is a good method to call after importing from TSV/CSV if you don't want to set types manually. If num_records is less than 1, all records in the table are inspected (this can take a long time for huge tables but should be done for all other tables).

If a column is a calculated column, its type is not set (columns with expressions do not have an explicit type).
Parameters:
num_records - The number of records to inspect before setting the type.
           (type=int)

index(self, *col_names)

Returns an index on this table for the given column name(s). This method allows you to find the record indices that match specific keys. If only one column name is specified, the index will have as many records as there are unique records in the column. If multiple columns are specified, the index will have as many records as there are unique combinations of the records in the columns.

Indices are used throughout Picalo internally and are not normally accessed by users. However, many analyses need to calculate indices directly, and exposing this method allows this behavior.

This method is efficient -- if the table data have not been modified since the last time a specific index was asked for, it uses the previously calculated index.
Parameters:
col_names - One or more column names (separated by commas) to calculate the unique index on.
           (type=str)

insert(self, *a, **k)

Inserts a new record at the given index location. The first parameter *must* be the index location to insert the record. The remaining parameters are the same as the append() method. Possible formats are (assuming you want to place the new record in the second row and push all existing records down one):

Format 1:
  • newrec = mytable3.insert(2) # insert before row 2
  • newrec['ID'] = 4
  • newrec['Name'] = 'Homer'
  • newrec['Salary'] = 15000
Format 2:
  • mytable.insert(2, 4, 'Homer', 1500) # insert before row 2
Format 3:
  • mytable3.insert(2, [4, 'Homer', 1500]) # insert before row 2
Format 4:
  • mytable3.insert(2, {'ID':5, 'Name':'Marge', 'Salary': 275000}) # insert before row 2
Format 5:
  • mytable3.insert(2, {0:5, 1:'Marge', 2: 275000}) # insert before row 2
Format 6:
  • mytable3.insert(2, ID=5, Name='Krusty', Salary=50000) # insert before row 2
You cannot mix formats in the same call.
Returns:
The new record object (that was inserted to the end of the table)
           (type=returns)

insert_calculated(self, index, name, expression)

Inserts a new, calculated column with records given by expression at the given index location. Calculated columns act as regular columns in all ways. Their records are 'active' meaning their records change when the result of the expression. In other words, they are recalculated each time they are used rather than being stored statically. This is similar to the way Excel functions always reflect the most updated data records.

Example:
>>> table = Table([('id', int)], [[1],[2],[4]])
>>> table.insert_calculated(0, 'plusone', "col000+1")
>>> table.view()
+---------+--------+
| plusone | col000 |
+---------+--------+
|       2 |      1 |
|       3 |      2 |
|       5 |      4 |
+---------+--------+
Parameters:
index - The index location of the new column. Previous column indices are incremented one to make room for the new column.
           (type=int)
name - The new column name
           (type=str)
expression - An expression that returns the record of the new field. As shown in the example, use rec to denote the current record being evaluated.
           (type=str)
Returns:
The new column object.
           (type=Column)

insert_calculated_static(self, index, name, column_type, expression)

Inserts a new, calculated column with records given by expression at the given index location. The records are calculated immediately using expression, and then they are static. In other words, this method calculates a new, regular column. The records are not 'active' in the sense that append_calculated() columns are active. When this method returns, the new column is the same as any other, non-calculated column.

Example:
>>> table = Table([('id', int)], [[1],[2],[4]])
>>> table.append_calculated('plusone', int, "col000 + 1")
>>> table.view()
+--------+---------+
| col000 | plusone |
+--------+---------+
|      1 |       2 |
|      2 |       3 |
|      4 |       5 |
+--------+---------+
Parameters:
index - The index location of the new column. Previous column indices are incremented one to make room for the new column.
           (type=int)
name - The new column name
           (type=str)
column_type - The type of the new column (str, Date, int, long, etc.)
           (type=type)
expression - An expression that returns the record of the new field. As shown in the example, use rec to denote the current record being evaluated.
           (type=str)
Returns:
The new column object.
           (type=Column)

insert_column(self, index, name, column_type, records=None)

Inserts a new column in the table at the given index location.
Parameters:
name - The new column name
           (type=str)
column_type - The new column type (int, float, DateTime, unicode, str, etc)
           (type=type)
records - A list of records to place into the cells of the new column (if a full Table, the first column is used)
           (type=list, Column, or Table)
Returns:
The new column object.
           (type=Column)

is_changed(self)

Returns whether the table has been changed since loading

is_filtered(self)

Returns True if this table has an active filter

is_readonly(self)

Returns whether this table is read only.
Returns:
Whether this table is read only.
           (type=bool)

iterator(self, respect_filter=True)

Returns an iterator to the Records in thistTable. This is normally achieved through:
>>> for record in mytable:
>>>   # do something with each record object
This method is provided to allow you to ignore the filter if you want. The regular iterator syntax (for record in mytable) always respects any active filters.
Returns:
An iterator to this Table.
           (type=iterator)

move_column(self, column, new_index)

Moves a column to another location in the table. A column can be moved in front of other columns or behind other columns with this method.

The column parameter is the name of the column to be moved, the index of the column to be moved, or the column object itself.

The new_index parameter is the new index for this column. This can be seen as the insertion point, or the column the moved column will be placed in front of. It can be specified as a column index, a column name, or a column object.
Parameters:
column - The name, index, or column object to be moved.
           (type=int/str/Column)
new_index - The name, index, or column object that the column will be placed before.
           (type=int/str/Column)

prettyprint(self, fp=None, center_columns=True, space_before=' ', space_after=' ', col_separator_char='|', row_separator_char='-', join_char='+', line_ending='\n', none='<N>', respect_filter=True)

Pretty prints the table to the given fp. Note that the preferred way to print a table is to call "table.view()", which opens the table in the Picalo GUI if possible, or uses view() if in console mode. In other words, you should normally use view() rather than this method.
Parameters:
fp - An open file pointer object. If None, defaults to standard output stream.
           (type=file)
center_columns - Whether to center columns or not.
           (type=bool)
space_before - An optional spacing between the leading column separator and the field record.
           (type=str)
space_after - An optional spacing between the field and the trailing column separator.
           (type=str)
col_separator_char - An optional column separator character to use in the printout.
           (type=str)
row_separator_char - An optional row separator character to use in the printout.
           (type=str)
join_char - An optional character to use when joining rows and columns.
           (type=str)
line_ending - An optional line ending character(s) to use.
           (type=str)
none - The record to print when cells are set to the special None record.
           (type=str)

record(self, index, respect_filter=True)

Retrieves the record at the given index. This is one of the most-used methods in the Picalo toolkit as it gives you access to records.

In keeping with most computer languages, Picalo indices are always zero-based. This may require a slight adjustment for some users, but it makes mathematical calculations much easier and has other implications. This means that record 1 is table[0], record 2 is table[1], and so forth.

Note that the shortcut way to access this method is the simple [n] notation, as in table[1] to access the second record. table.record() is rarely called as the shortcut is preferred instead.

For advanced users: Index can also be a slice, as in table[2:5] to return a new Picalo table including only records 2, 3, and 4. See the Python documentation for more information on slices.

The method respects any filters on the table by default. This can be overridden to ignore the filter.

Example:
>>> table = Table([('id', int)], [[1],[2],[3],[4]])
>>> table2 = table[1]
>>> # table2 is now a Record object pointing at [2]
Example 2:
>>> table = Table([('id', int)], [[1],[2],[3],[4]])
>>> print table[1]['col000']
2
Parameters:
index - The zero-based index of the record to pull.
           (type=int)
Returns:
A Picalo Record object, which allows access to members via column name.
           (type=Record)

record_count(self, respect_filter=True)

Returns the number of records in this table. The method respects any active filters on the table by default.
Returns:
The number of records in the table.
           (type=int)

reorder_columns(self, columns)

Reorders the columns according to the given list. This is an alternative to move_column. If you know the exact order you want the columns in, use this method to explicitly set them.

The columns parameter is a list giving the new order. Its items can be current column indices, names, or columb objects.
Parameters:
columns - A list giving the new column order (use column names, not indices).
           (type=list)

save(self, filename, respect_filter=False)

Saves this table in native Picalo format. This is the preferred format to save tables in because all column types, formulas, and so forth are saved.
Parameters:
filename - The filename to save to. This can also be an open stream.
           (type=str @param respect_filter Whether to save the entire file or only those rows available through any current filter. @type respect_filter bool)

save_csv(self, filename, line_ending='\n', none='', encoding='utf-8', respect_filter=False)

Saves this table to a Comma Separated Values (CSV) text file. CSV is an industry-standard way of transferring data between applications. This is the preferred way of exporting data from Picalo.

Note that although this is the preferred export method, it has some limitations. These are limitations of the format rather than limitations of Picalo:
  • No type information is saved to the file. All data is essentially turned into strings.
  • Be sure to use the correct encoding if using international languages.
  • Different standards for CSV exist (that's the nice thing about standards :). This export uses the Microsoft version.
Note that Microsoft Office seems to like CSV files better than TSV files.
Parameters:
filename - A file name or a file pointer to an open file. Using the file name string directly is suggested since it ensures the file is opened correctly for reading in CSV.
           (type=str)
line_ending - An optional line ending to separate rows with
           (type=str)
none - An optional parameter specifying what to write for cells that have the None record.
           (type=str)
encoding - The unicode encoding to use for international or special characters. For example, Microsoft applications like to use special characters for double quotes rather than the standard characters. Unicode (the default) handles these nicely.
           (type=str @param respect_filter Whether to save the entire file or only those rows available through any current filter. @type respect_filter bool)

save_delimited(self, filename, delimiter=',', qualifier='"', line_ending='\n', none='', encoding='utf-8', respect_filter=False)

Saves this table to a delimited text file. This method allows the specification of different types of delimiters and qualifiers.

This method is for advanced users. Most users should call save_tsv, save_csv, or save_fixed to save using one of the accepted text formats. See these methods for more information.
Parameters:
filename - A file name or a file pointer to an open file. Using the file name string directly is suggested since it ensures the file is opened correctly for reading in CSV.
           (type=str)
delimiter - An optional field delimiter character
           (type=str)
qualifier - An optional qualifier to use when delimiters exist in field records
           (type=str)
line_ending - An optional line ending to separate rows with
           (type=str)
none - An optional parameter specifying what to write for cells that have the None record.
           (type=str)
encoding - The unicode encoding to use for international or special characters. For example, Microsoft applications like to use special characters for double quotes rather than the standard characters. Unicode (the default) handles these nicely.
           (type=str @param respect_filter Whether to save the entire file or only those rows available through any current filter. @type respect_filter bool)

save_excel(self, filename, none='', respect_filter=False)

Saves this table to a Microsoft Excel 97+ file.
Parameters:
filename - A file name or a file pointer to an open file. Using the file name string directly is suggested since it ensures the file is opened correctly for reading in CSV.
           (type=str)
none - An optional parameter specifying what to write for cells that have the None record.
           (type=str @param respect_filter Whether to save the entire file or only those rows available through any current filter. @type respect_filter bool)

save_fixed(self, filename, line_ending='\n', none='', respect_filter=False)

Saves this table to a fixed width text file. Fixed width files pad column records with extra spaces so they are easier to read.

You should normally prefer CSV and TSV export formats to fixed as they have less limitations. Fixed format was widely used in the early days of computers, and some servers still use the format.
Parameters:
filename - A file name or a file pointer to an open file. Using the file name string directly is suggested since it ensures the file is opened correctly for reading in CSV.
           (type=str)
line_ending - An optional line ending to separate rows with
           (type=str)
none - An optional parameter specifying what to write for cells that have the None record.
           (type=str @param respect_filter Whether to save the entire file or only those rows available through any current filter. @type respect_filter bool)

save_tsv(self, filename, line_ending='\n', none='', encoding='utf-8', respect_filter=False)

Saves this table to a Tab Separated Values (TSV) text file. TSV is an industry-standard way of transferring data between applications.

Note that although this is the preferred export method, it has some limitations. These are limitations of the format rather than limitations of Picalo:
  • No type information is saved to the file. All data is essentially turned into strings.
  • Be sure to use the correct encoding if using international languages.
  • Different standards for TSV exist (that's the nice thing about standards :). This export uses the Microsoft version.
Note that Microsoft Office seems to like CSV files better than TSV files.
Parameters:
filename - A file name or a file pointer to an open file. Using the file name string directly is suggested since it ensures the file is opened correctly for reading in CSV.
           (type=str)
line_ending - An optional line ending to separate rows with
           (type=str)
none - An optional parameter specifying what to write for cells that have the None record.
           (type=str)
encoding - The unicode encoding to use for international or special characters. For example, Microsoft applications like to use special characters for double quotes rather than the standard characters. Unicode (the default) handles these nicely.
           (type=str)

save_xml(self, filename, line_ending='\n', indent='\t', compact=False, none='', respect_filter=False)

Saves this table to an XML file using a pre-defined schema. If you need to save to a different schema, use the xml.dom.minidom class directly.
Parameters:
filename - A file name or a file pointer to an open file. Using the file name string directly is suggested since it ensures the file is opened correctly for reading in CSV.
           (type=str)
line_ending - An optional line ending to separate rows with (when compact is False)
           (type=str)
indent - The character(s) to use for indenting (when compact is False)
           (type=str)
compact - Whether to compact the XML or make it "pretty" with whitespace
           (type=bool)
none - An optional parameter specifying what to write for cells that have the None record.
           (type=str @param respect_filter Whether to save the entire file or only those rows available through any current filter. @type respect_filter bool)

set_changed(self, changed)

Sets whether the class has been changed since loading. This is not normally called by users.

set_format(self, column, format=None)

Sets the format of this column.  The format is used for printing the record 
and showing the record in the Picalo GUI.

The format should be a Picalo expression that evaluates to a string.  Use the
'record' variable for the record of the current cell.

Note that this is not an input mask.  It doesn't affect the internal record of 
the field records.  It only affects how it is displayed on the screen.

Example:
  # shows the current record in uppercase
  table.set_format('Salary', "record.upper()")

@param column:  The column name or index to set the type of
@type  column:  str
@param format:  A Picalo expression that evaluates to a string
@type  format:  str

set_name(self, column, name)

Changes the name of an existing column. The column name must be a valid Picalo name and must be unique to other column names in the table.

set_readonly(self, readonly_flag=False)

Sets the read only status of this table. Tables that are read only cannot be modified. Normally, tables are initially not read only (i.e. can be modified). The only exception is tables loaded from databases, which are read only.
Parameters:
readonly_flag - True or False, depending upon whether the table should be read only or not.
           (type=bool)

set_type(self, column, column_type=None, format=None, expression=None)

Sets the type of a column. The type must be a valid <type> object, such as int, float, str, unicode, DateTime, etc. All records in this column will be converted to this new type.

The format is an optional format to be used for printing the record and showing the record in the Pialo GUI.
Parameters:
column - The column name or index to set the type of
           (type=str)
column_type - The new type of this column.
           (type=type)
format - A Picalo expression that evaluates to a string
           (type=str)
expression - A Picalo expression that calculates this column.

sort(self, cmp=None, key=None, reverse=False)

Sorts this table with optional arguments.
Parameters:
cmp - An optional function that compares two items
           (type=function)
key - A function that takes a single item and returns a version of it for use in sorting.
           (type=function)
reverse - Whether to sort in reverse
           (type=bool)

structure(self)

Returns the structure of this table, including column names, input and output types, and general statistics.
Returns:
A Picalo table describing the structure of this table.
           (type=Table)

view(self)

Opens a spreadsheet-view of the table if Picalo is being run in GUI mode. If Picalo is being run in console mode, it redirects to prettyprint(). This is the preferred way of viewing the data in a table.

_add_listener(self, listener)

Adds a listener to the table. Will be notified when data changes occur. The listener should be a callable/function of form callback(table). For efficiency reasons and because we don't need it right now, the col and row is not reported.

_calculate_columns_map(self)

Calculates the columns map based upon the current columns. This method should not be called externally.

_check_page_size(self)

Checks the current page size to see if we need to split it into two pages

_get_filtered_index(self, index)

Returns the filtered index of the given index, if a filter is in place. This method is not thread-safe.

_invalidate_indexes(self)

Invalidates the indices already calculated on this table. This occurs anytime data are modified in this table

_notify_listeners(self, level=1)

Notifies listeners that we've had a change

_populate_record(self, rec, *a, **k)

Populates a record with data. Examples:
  • Format 1: mytable._populate_record(val1, val2)
  • Format 2: mytable._populate_record([val1, val2])
  • Format 3: mytable._populate_record(head1=val1, head2=val2)
  • Format 4: mytable._populate_record({'head1':val1, 'head2':val2})
  • Format 5: mytable._populate_record({0:val1, 1:val2})

You cannot mix formats in the same call.

This method is used internall and should not be called by user code.

_remove_listener(self, listener)

Removes a listener from the table.

_save_dialect(self, filename, dialect, none='', encoding='utf-8', respect_filter=False)

Internal function to save according to a specific dialect (see the csv module docs)

_set_cursor_datasource(self, cursor)

Sets the given cursor as the datasource for this table.

_swap_page(self, new_pageindex)

Swaps the current page for a new one

_swap_page_to_index(self, key)

Swaps the current page to the one including the given record

_update_filter_index(self)

Updates the filter index.

Generated by Epydoc 2.1 on Mon Aug 20 05:38:17 2007 http://epydoc.sf.net