Package glue :: Package ligolw :: Module table :: Class Table
[hide private]
[frames] | no frames]

Class Table

source code

     object --+            
              |            
 ligolw.Element --+        
                  |        
ligolw.EmptyElement --+    
                      |    
           ligolw.Table --+
                          |
             object --+   |
                      |   |
                   list --+
                          |
                         Table
Known Subclasses:

High-level Table element that knows about its columns and rows.

Nested Classes [hide private]
  RowType
Helpful parent class for row objects.
  TableName
Instance Methods [hide private]
new empty list
__init__(self, *args)
Initialize
source code
 
_end_of_columns(self)
Called during parsing to indicate that the last Column child element has been added.
source code
 
_end_of_rows(self)
Called during parsing to indicate that the last row has been added.
source code
 
_update_column_info(self)
Used for validation during parsing, and additional book-keeping.
source code
 
_verifyChildren(self, i)
Used for validation during parsing, and additional book-keeping.
source code
 
appendColumn(self, name)
Append a Column element named "name" to the table.
source code
 
appendRow(self, *args, **kwargs)
Create and append a new row to this table, then return it
source code
 
applyKeyMapping(self, mapping)
Used as the second half of the key reassignment algorithm.
source code
 
copy(self)
Construct and return a new Table document subtree whose structure is the same as this table, that is it has the same columns etc..
source code
 
endElement(self)
Method invoked by document parser when it encounters the end-of-element event.
source code
 
getColumnByName(self, name)
Retrieve and return the Column child element named name.
source code
 
removeChild(self, child)
Remove a child from this element.
source code
 
sync_next_id(self)
Determines the highest-numbered ID in this table, and sets the table's .next_id attribute to the next highest ID in sequence.
source code
 
unlink(self)
Break internal references within the document tree rooted on this element to promote garbage collection.
source code
 
updateKeyMapping(self, mapping)
Used as the first half of the row key reassignment algorithm.
source code

Inherited from ligolw.EmptyElement: appendData

Inherited from ligolw.Element: appendChild, end_tag, getAttribute, getChildrenByAttributes, getElements, getElementsByTagName, hasAttribute, insertBefore, removeAttribute, replaceChild, setAttribute, start_tag, write

Inherited from list: __add__, __contains__, __delitem__, __delslice__, __eq__, __ge__, __getattribute__, __getitem__, __getslice__, __gt__, __iadd__, __imul__, __iter__, __le__, __len__, __lt__, __mul__, __ne__, __new__, __repr__, __reversed__, __rmul__, __setitem__, __setslice__, __sizeof__, append, count, extend, index, insert, pop, remove, reverse, sort

Inherited from object: __delattr__, __format__, __reduce__, __reduce_ex__, __setattr__, __str__, __subclasshook__

Class Methods [hide private]
 
CheckElement(cls, elem)
Return True if element is a Table element whose Name attribute matches the .tableName attribute of this class ; return False otherwise.
source code
 
CheckProperties(cls, tagname, attrs)
Return True if tagname and attrs are the XML tag name and element attributes, respectively, of a Table element whose Name attribute matches the .tableName attribute of this class; return False otherwise.
source code
 
getTablesByName(cls, elem, name)
Return a list of Table elements named name under elem.
source code
 
get_next_id(cls)
Returns the current value of the next_id class attribute, and increments the next_id class attribute by 1.
source code
 
get_table(cls, xmldoc)
Equivalent to the module-level function get_table(), but uses the .tableName attribute of this class to provide the name of the table to search for.
source code
 
reset_next_id(cls)
If the current value of the next_id class attribute is not None then set it to 0, otherwise it is left unmodified.
source code
 
set_next_id(cls, id)
Sets the value of the next_id class attribute.
source code

Inherited from ligolw.Element: validattributes

Class Variables [hide private]
  constraints = None
hash(x)
  how_to_index = None
hash(x)
  interncolumns = None
hash(x)
  loadcolumns = None
hash(x)
  next_id = None
hash(x)
  validcolumns = None
hash(x)

Inherited from ligolw.Table: tagName, validchildren

Inherited from list: __hash__

Properties [hide private]
  Name
The "Name" attribute.

Inherited from ligolw.Table: Type

Inherited from object: __class__

Method Details [hide private]

CheckElement(cls, elem)
Class Method

source code 

Return True if element is a Table element whose Name attribute matches the .tableName attribute of this class ; return False otherwise. See also .CheckProperties().

CheckProperties(cls, tagname, attrs)
Class Method

source code 

Return True if tagname and attrs are the XML tag name and element attributes, respectively, of a Table element whose Name attribute matches the .tableName attribute of this class; return False otherwise. The Table parent class does not provide a .tableName attribute, but sub-classes, especially those in lsctables.py, do provide a value for that attribute. See also .CheckElement()

Example:

>>> import lsctables
>>> lsctables.ProcessTable.CheckProperties(u"Table", {u"Name": u"process:table"})
True

__init__(self, *args)
(Constructor)

source code 

Initialize

Returns: new empty list
Overrides: object.__init__

_end_of_columns(self)

source code 

Called during parsing to indicate that the last Column child element has been added. Subclasses can override this to perform any special action that should occur following the addition of the last Column element.

_end_of_rows(self)

source code 

Called during parsing to indicate that the last row has been added. Subclasses can override this to perform any special action that should occur following the addition of the last row.

_update_column_info(self)

source code 

Used for validation during parsing, and additional book-keeping. For internal use only.

_verifyChildren(self, i)

source code 

Used for validation during parsing, and additional book-keeping. For internal use only.

Overrides: ligolw.Element._verifyChildren

appendColumn(self, name)

source code 

Append a Column element named "name" to the table. Returns the new child. Raises ValueError if the table already has a column by that name, and KeyError if the validcolumns attribute of this table does not contain an entry for a column by that name.

Note that the name string is assumed to be "pre-stripped", that is it is the significant portion of the elements Name attribute. The Column element's Name attribute will be constructed by pre-pending the stripped Table element's name and a colon.

Example:

>>> import lsctables
>>> process_table = lsctables.New(lsctables.ProcessTable, [])
>>> col = process_table.appendColumn("program")
>>> col.getAttribute("Name")
u'process:program'
>>> col.Name
u'program'

appendRow(self, *args, **kwargs)

source code 

Create and append a new row to this table, then return it

All positional and keyword arguments are passed to the RowType constructor for this table.

applyKeyMapping(self, mapping)

source code 

Used as the second half of the key reassignment algorithm. Loops over each row in the table, replacing references to old row keys with the new values from the mapping.

copy(self)

source code 

Construct and return a new Table document subtree whose structure is the same as this table, that is it has the same columns etc.. The rows are not copied. Note that a fair amount of metadata is shared between the original and new tables. In particular, a copy of the Table object itself is created (but with no rows), and copies of the child nodes are created. All other object references are shared between the two instances, such as the RowType attribute on the Table object.

endElement(self)

source code 

Method invoked by document parser when it encounters the end-of-element event.

Overrides: ligolw.Element.endElement
(inherited documentation)

getColumnByName(self, name)

source code 

Retrieve and return the Column child element named name. The comparison is done using the stripped names. Raises KeyError if this table has no column by that name.

Example:

>>> import lsctables
>>> tbl = lsctables.New(lsctables.SnglInspiralTable)
>>> col = tbl.getColumnByName("mass1")

get_next_id(cls)
Class Method

source code 

Returns the current value of the next_id class attribute, and increments the next_id class attribute by 1. Raises ValueError if the table does not have an ID generator associated with it.

get_table(cls, xmldoc)
Class Method

source code 

Equivalent to the module-level function get_table(), but uses the .tableName attribute of this class to provide the name of the table to search for. The Table parent class does not provide a .tableName attribute, but sub-classes, especially those in lsctables.py, do provide a value for that attribute, and in those cases this class method provides a cleaner way to retrieve them.

Example:

>>> import ligolw
>>> import lsctables
>>> xmldoc = ligolw.Document()
>>> xmldoc.appendChild(ligolw.LIGO_LW()).appendChild(lsctables.New(lsctables.SnglInspiralTable))
[]
>>> sngl_inspiral_table = lsctables.SnglInspiralTable.get_table(xmldoc)

removeChild(self, child)

source code 

Remove a child from this element. The child element is returned, and it's parentNode element is reset.

Overrides: ligolw.Element.removeChild

reset_next_id(cls)
Class Method

source code 

If the current value of the next_id class attribute is not None then set it to 0, otherwise it is left unmodified.

Example:

>>> import lsctables
>>> for cls in lsctables.TableByName.values(): cls.reset_next_id()

set_next_id(cls, id)
Class Method

source code 

Sets the value of the next_id class attribute. This is a convenience function to help prevent accidentally assigning a value to an instance attribute instead of the class attribute.

sync_next_id(self)

source code 

Determines the highest-numbered ID in this table, and sets the table's .next_id attribute to the next highest ID in sequence. If the .next_id attribute is already set to a value greater than the highest value found, then it is left unmodified. The return value is the ID identified by this method. If the table's .next_id attribute is None, then this function is a no-op.

Note that tables of the same name typically share a common .next_id attribute (it is a class attribute, not an attribute of each instance) so that IDs can be generated that are unique across all tables in the document. Running sync_next_id() on all the tables in a document that are of the same type will have the effect of setting the ID to the next ID higher than any ID in any of those tables.

Example:

>>> import lsctables
>>> tbl = lsctables.New(lsctables.ProcessTable)
>>> print(tbl.sync_next_id())
process:process_id:0

unlink(self)

source code 

Break internal references within the document tree rooted on this element to promote garbage collection.

Overrides: ligolw.Element.unlink

updateKeyMapping(self, mapping)

source code 

Used as the first half of the row key reassignment algorithm. Accepts a dictionary mapping old key --> new key. Iterates over the rows in this table, using the table's next_id attribute to assign a new ID to each row, recording the changes in the mapping. Returns the mapping. Raises ValueError if the table's next_id attribute is None.


Property Details [hide private]

Name

The "Name" attribute.

Get Method:
unreachable.getter(self)
Set Method:
unreachable.setter(self, value)
Delete Method:
unreachable.deleter(self)