Class Column
source code
object --+
|
ligolw.Element --+
|
ligolw.EmptyElement --+
|
ligolw.Column --+
|
Column
High-level column element that provides list-like access to the values
in a column.
Example:
>>> from xml.sax.xmlreader import AttributesImpl
>>> import sys
>>> tbl = Table(AttributesImpl({u"Name": u"test"}))
>>> col = tbl.appendChild(Column(AttributesImpl({u"Name": u"test:snr", u"Type": u"real_8"})))
>>> tbl.appendChild(TableStream(AttributesImpl({u"Name": u"test"})))
<glue.ligolw.table.TableStream object at ...>
>>> tbl._update_column_info()
>>> col.Name
u'snr'
>>> col.Type
u'real_8'
>>>
>>> tbl.append(tbl.RowType())
>>> tbl.append(tbl.RowType())
>>> tbl.append(tbl.RowType())
>>>
>>> col[:] = [8.0, 10.0, 12.0]
>>> col[:]
[8.0, 10.0, 12.0]
>>> col.asarray()
array([ 8., 10., 12.])
>>> tbl.write(sys.stdout)
<Table Name="test">
<Column Type="real_8" Name="test:snr"/>
<Stream Name="test">
8,
10,
12
</Stream>
</Table>
>>> col.index(10)
1
>>> 12 in col
True
>>> col[0] = 9.
>>> col[1] = 9.
>>> col[2] = 9.
>>> tbl.write(sys.stdout)
<Table Name="test">
<Column Type="real_8" Name="test:snr"/>
<Stream Name="test">
9,
9,
9
</Stream>
</Table>
>>> col.count(9)
3
NOTE: the .Name attribute returns the stripped "Name"
attribute of the element, e.g. with the table suffix removed, but when
assigning to the .Name attribute the value provided is stored without
modification, i.e. there is no attempt to reattach the table's name to
the string. The calling code is responsible for doing the correct
manipulations. Therefore, the assignment operation below
>>> col.Name, col.getAttribute("Name")
(u'snr', u'test:snr')
>>> col.Name = col.Name
>>> col.Name, col.getAttribute("Name")
(u'snr', u'snr')
does not preserve the value of the "Name" attribute (though
it does preserve the stripped form reported by the .Name property). This
asymmetry is necessary because the correct table name string to reattach
to the attribute's value cannot always be known, e.g., if the Column
object is not part of an XML tree and does not have a parent node.
|
__contains__(self,
value)
Returns True or False if there is or is not, respectively, a row
containing val in this column. |
source code
|
|
|
|
|
__getitem__(self,
i)
Retrieve the value in this column in row i. |
source code
|
|
|
__iter__(self)
Return an iterator object for iterating over values in this column. |
source code
|
|
|
__len__(self)
The number of values in this column. |
source code
|
|
|
|
|
|
|
count(self,
value)
Return the number of rows with this column equal to value. |
source code
|
|
|
index(self,
value)
Return the smallest index of the row(s) with this column equal to
value. |
source code
|
|
Inherited from ligolw.Column :
end_tag ,
start_tag ,
write
Inherited from ligolw.EmptyElement :
appendData
Inherited from ligolw.Element :
__init__ ,
appendChild ,
endElement ,
getAttribute ,
getChildrenByAttributes ,
getElements ,
getElementsByTagName ,
hasAttribute ,
insertBefore ,
removeAttribute ,
removeChild ,
replaceChild ,
setAttribute ,
unlink
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
__setitem__(self,
i,
value)
(Index assignment operator)
| source code
|
Set the value in this column in row i. i may be a slice.
NOTE: Unlike normal Python lists, the length of the Column cannot be
changed as it is tied to the number of rows in the Table. Therefore, if
i is a slice, value should be an iterable with exactly the correct number
of items. No check is performed to ensure that this is true: if value
contains too many items the extras will be ignored, and if value contains
too few items only as many rows will be updated as there are items.
|
Construct a numpy array from this column. Note that this creates a
copy of the data, so modifications made to the array will *not* be
recorded in the original document.
|
Name
The "Name" attribute.
- Get Method:
- unreachable.getter(self)
- Set Method:
- unreachable.setter(self,
value)
- Delete Method:
- unreachable.deleter(self)
|