Package xdp :: Module dataset :: Class Data
[show private | hide private]
[frames | no frames]

Class Data

Known Subclasses:
ExperimentData, XafsData

Store columns of data and their associated names.

These columns can be maniplulated by the get(), add(), and set() methods or by accessing the columns as though they are attributes of the object.
Method Summary
  __init__(self, **kwds)
Create an empty dataset.
  __getattr__(self, name)
Allow columns to be accessed as attributes.
  __setattr__(self, name, value)
Allow columns to be set as attributes.
  add(self, name, vector)
Create a new column of data.
  addColumn(self, name, vector)
Create a new column of data.
list of strings columns(self)
Retrieve a list of the column names.
xdp.Data copy(self, deep)
Create a copy of this dataset.
any evaluate(self, expr)
Evaluate a Python expression using this dataset's column names
Numeric vector get(self, name)
Retrieve a column's data.
Numeric vector getColumn(self, name)
Retrieve a column's data.
list of strings getColumnNames(self)
Retrieve a list of the column names.
Numeric matrix getMatrix(self)
Construct a matrix out of this dataset.
bool has(self, name)
Check for the presence of a column.
bool hasColumn(self, name)
Check for the presence of a column.
  remove(self, name)
Remove a column.
  removeColumn(self, name)
Remove a column.
  rename(self, name, newName)
Rename a column.
  renameColumn(self, name, newName)
Rename a column.
  set(self, name, vector)
Assign data to a column.
  setColumn(self, name, vector)
Assign data to a column.
Numeric vector __getByIndex(self, index)
Retrieve data by column number.

string or None

Attempt to convert the object 'name' into a valid column name by interpreting it as a column number. A return value of None indicates that 'name' was not a valid column number.
__getIndex(self, name)
Convert a value from a column number into a column name.
  __removeByIndex(self, index)
Remove a column by its column number.
  __setByIndex(self, index, vector)
Assign data by column number.

Class Variable Summary
compiled regular expression COLNAMES: used by Data.evaluate to match and replace the @X column names in expressions
compiled regular expression COLNUMS: used by Data.evaluate to match and replace the @X column numbers in expressions
dict EVAL_NAMESPACE: used by Data.evaluate as the default namespace for evaluating Python expressions

Method Details

__init__(self, **kwds)
(Constructor)

Create an empty dataset.

If keyword arguments are provided, they are interpreted as column definitions and are used to populate the dataset.
Parameters:
kwds - column name <-> vector pairs
           (type=dict mapping strings onto vectors)

__getattr__(self, name)
(Qualification operator)

Allow columns to be accessed as attributes.
Parameters:
name - column name (attribute name)
           (type=string)

Note: Columns must already exist before the can be fetched using this method.

__setattr__(self, name, value)

Allow columns to be set as attributes.
Parameters:
name - column name (attribute name)
           (type=string)
value - column data (attribute value)
           (type=Numeric vector (any))

Note: Columns must already exist before the can be updated using this method.

To Do: same checks as for setColumn

add(self, name, vector)

Create a new column of data.
Parameters:
name - new column's name
           (type=string)
vector - new column's data
           (type=Numeric vector)
Raises:
ColumnNameError - the column name already exists

Depreciated: use addColumn instead

addColumn(self, name, vector)

Create a new column of data.
Parameters:
name - new column's name
           (type=string)
vector - new column's data
           (type=Numeric vector)
Raises:
ColumnNameError - the column name already exists

To Do:

  • check that the length of vector matches the other columns
  • check that name is a valid column name

columns(self)

Retrieve a list of the column names.
Returns:
names of this dataset's columns
           (type=list of strings)

Depreciated: use getColumnNames instead

copy(self, deep=1)

Create a copy of this dataset.
Parameters:
deep - make a deep copy of this dataset by making copies of all of the vectors
           (type=bool (defaults to true))
Returns:
copy of this dataset
           (type=xdp.Data)

evaluate(self, expr)

Evaluate a Python expression using this dataset's column names

Column names are prefixes by an at sign, and may contain the name (@If/@Io) or number (@4/@2).

The following constants and functions are available for use within the expression:
  • intint
  • floatfloat
  • complexcomplex
  • pimath.pi
  • emath.e
  • absNumeric.absolute
  • arccosNumeric.arccos
  • arccoshNumeric.arccosh
  • arcsinNumeric.arcsin
  • arcsinhNumeric.arcsinh
  • arctanNumeric.arctan
  • arctanhNumeric.arctanh
  • cosNumeric.cos
  • coshNumeric.cosh
  • expNumeric.exp
  • logNumeric.log
  • log10Numeric.log10
  • powerNumeric.power
  • sinNumeric.sin
  • sinhNumeric.sinh
  • sqrtNumeric.sqrt
  • tanNumeric.tan
  • tanhNumeric.tanh
All of the functions from Numeric are ufuncs; they will operate correctly on vectors.
Parameters:
expr - python expression
           (type=string)
Returns:
result of the expression
           (type=any)
Raises:
EvaluationError - the expression could not be compiled or caused an exception during evaluation
ColumnNameError - the expression contained an invalid column name or number

get(self, name)

Retrieve a column's data.

name may be the column's name, a column index, or a string containing a column index.
Parameters:
name - column name
           (type=string or int)
Returns:
column data
           (type=Numeric vector)
Raises:
ColumnNameError - there is no column name and name is not a valid column number

Depreciated: use getColumn instead

Note: Column indices start at 1.

getColumn(self, name)

Retrieve a column's data.

name may be the column's name, a column index, or a string containing a column index.
Parameters:
name - column name
           (type=string or int)
Returns:
column data
           (type=Numeric vector)
Raises:
ColumnNameError - there is no column name and name is not a valid column number

Note: Column indices start at 1.

getColumnNames(self)

Retrieve a list of the column names.
Returns:
names of this dataset's columns
           (type=list of strings)

getMatrix(self)

Construct a matrix out of this dataset.
Returns:
matrix containing all of this dataset's columns
           (type=Numeric matrix)

Note: Until addColumn and setColumn check that the size of column vectors is valid, this method could concievably throw a ValueError.

has(self, name)

Check for the presence of a column.
Parameters:
name - column to check for
           (type=string)
Returns:
whether or not this dataset has a column name
           (type=bool)

Depreciated: use hasColumn instead

hasColumn(self, name)

Check for the presence of a column.
Parameters:
name - column to check for
           (type=string)
Returns:
whether or not this dataset has a column name
           (type=bool)

remove(self, name)

Remove a column.
Parameters:
name - column name to remove
           (type=string)
Raises:
ColumnNameError - the column name does not exist

Depreciated: use removeColumn instead

removeColumn(self, name)

Remove a column.
Parameters:
name - column name or index to remove
           (type=int or string)
Raises:
ColumnNameError - the column name does not exist

rename(self, name, newName)

Rename a column.
Parameters:
name - column to rename
           (type=string)
newName - new column name
           (type=string)
Raises:
TypeError - either name or newName is not a string
ColumnNameError - the column name does not exist

Depreciated: use renameColumn instead

renameColumn(self, name, newName)

Rename a column.
Parameters:
name - column to rename
           (type=string)
newName - new column name
           (type=string)
Raises:
TypeError - either name or newName is not a string
ColumnNameError - the column name does not exist

To Do: what is newName already exists?

set(self, name, vector)

Assign data to a column. If the column does not exist, it will be created.
Parameters:
name - column name
           (type=string)
vector - new column data
           (type=Numeric vector)

Depreciated: use setColumn instead

setColumn(self, name, vector)

Assign data to a column.

If the column does not exist, it will be created.
Parameters:
name - column name
           (type=int or string)
vector - new column data
           (type=Numeric vector)

To Do: same checks as for addColumn

__getByIndex(self, index)

Retrieve data by column number.
Parameters:
index - column number
           (type=int or string)
Returns:
column data
           (type=Numeric vector)
Raises:
ColumnNameError - the column number supplied was invalid

__getIndex(self, name)

Convert a value from a column number into a column name.

This method returns None if name is not a valid column number.
Parameters:
name - column number
           (type=int or string)
Returns:
column name
           (type=

string or None

Attempt to convert the object 'name' into a valid column name by interpreting it as a column number. A return value of None indicates that 'name' was not a valid column number.)

__removeByIndex(self, index)

Remove a column by its column number.
Parameters:
index - column number
           (type=int or string)
Raises:
ColumnNameError - the column number supplied was invalid

__setByIndex(self, index, vector)

Assign data by column number.
Parameters:
index - column number
           (type=int or string)
vector - new column data
           (type=Numeric vector)
Raises:
ColumnNameError - the column number supplied was invalid

Class Variable Details

COLNAMES

used by Data.evaluate to match and replace the @X column names in expressions
Type:
compiled regular expression
Value:
(@([a-zA-Z_][a-zA-Z0-9_]*))                                            

COLNUMS

used by Data.evaluate to match and replace the @X column numbers in expressions
Type:
compiled regular expression
Value:
(@(\d+))                                                               

EVAL_NAMESPACE

used by Data.evaluate as the default namespace for evaluating Python expressions
Type:
dict
Value:
{'abs': <ufunc 'absolute'>,
 'arccos': <ufunc 'arccos'>,
 'arccosh': <ufunc 'arccosh'>,
 'arcsin': <ufunc 'arcsin'>,
 'arcsinh': <ufunc 'arcsinh'>,
 'arctan': <ufunc 'arctan'>,
 'arctanh': <ufunc 'arctanh'>,
 'complex': <type 'complex'>,
...                                                                    

Generated by Epydoc 2.1 on Wed Jul 20 11:51:06 2005 http://epydoc.sf.net