Module Table :: Class Cols
[show private | hide private]
[frames | no frames]

Type Cols

object --+
         |
        Cols


Provides a natural naming and container interface for columns.


Method Summary
  __init__(self, table)
Create the container to keep the column information.
  __getitem__(self, key)
Returns a column row, column slice or a sub-column.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Method Details

__init__(self, table)
(Constructor)

Create the container to keep the column information.

table is the parent Table object.

This constructor creates one attribute for each column in table. If the column is non-nested, the attribute will point to a Column object. If the column is nested, the attribute will point to another Cols object.

Following are some examples showing how these attributes can be used to 'fake' a natural naming when accessing nested columns.

Example 1

Get a non-nested column:

>>> id = table.cols.id
Cols(table.cols.id)
>>> id[:]
array([1, 2], type=Int64)

Example 2

Get a nested column:

>>> info = table.cols.info
Cols(table.cols.info)
>>> info[:]
array(
[('a1', 1j),
 ('a2', 1+.1j)],
formats=['a2', 'Complex64'],
shape=2,
names=['info', ['name', 'value']])

Example 3

Get a deeply nested column:

>>> value = table.cols.info.value
Column(table.cols.info.value)  # Note that this is plain Column!
>>> value[:]
array([ 0.+1.j ,  1.+0.1j])
Overrides:
__builtin__.object.__init__

__getitem__(self, key)
(Indexing operator)

Returns a column row, column slice or a sub-column.

It takes different actions depending on the type of the ``key parameter:

If key is an integer, the corresponding column is returned as a Record or NestedRecord object, whatever is most appropriate. If key is a slice, the row slice determined by key is returned as a RecArray or NestedRecArray object, whatever is most appropriate.

Finally, if key is a string, it is interpreted as a column name in the table, and, if it is a plain field (i.e. has not a nested structure), a Column object is returned. If key has a nested structure (nested column), it returns another Cols object that can be used as a container for accessing its nested columns. If key has a '/' character on it, this is interpreted as a separator for nested fields (see examples).

Example 1

Get table row #0:

>>> table.cols[0]   # equivalent to table[0]
array(
[(1, (0.5, 1.0), ('a1', 1j))],
formats=['Int64', '(2,)Float32', ['a2', 'Complex64']],
shape=1,
names=['id', 'pos', ('info', ['name', 'value'])])

Example 2

Get a non-nested column:

>>> id = table.cols['id']
Cols(table.cols.id)
>>> id[:]
array([1, 2], type=Int64)

Example 3

Get a nested column:

>>> info = table.cols['info']
Cols(table.cols.info)
>>> info[:]
array(
[('a1', 1j),
 ('a2', 1+.1j)],
formats=['a2', 'Complex64'],
shape=2,
names=['info', ['name', 'value']])

Example 4

Get a deeply nested column (using a mix of natural naming and getitem):

>>> value = table.cols.info['value']
Column(table.cols.info.value)     # Note that this is plain Column!
>>> value[1]
(1+0.10000000000000001j)
>>> value[:]
array([ 0.+1.j ,  1.+0.1j])

Generated by Epydoc 2.1 on Thu Apr 21 13:11:49 2005 http://epydoc.sf.net