Column¶
- class igwn_ligolw.ligolw.Column(attrs=None)¶
Bases:
EmptyElementColumn element. Provides list-like access to the values in a column.
Example:
>>> from xml.sax.xmlreader import AttributesImpl >>> import sys >>> tbl = Table(AttributesImpl({"Name": "test"})) >>> col = tbl.appendChild(Column(AttributesImpl({"Name": "test:snr", "Type": "real_8"}))) >>> tbl.appendChild(tbl.Stream(AttributesImpl({"Name": "test"}))) <igwn_ligolw.ligolw.Table.Stream object at ...> >>> print(col.Name) snr >>> print(col.Type) real_8 >>> print(col.table_name) test >>> # append 3 rows (with nothing in them) >>> tbl.append(tbl.RowType()) >>> tbl.append(tbl.RowType()) >>> tbl.append(tbl.RowType()) >>> # assign values to the rows, in order, in this column >>> 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 Name="test:snr" Type="real_8"/> <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 Name="test:snr" Type="real_8"/> <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 name prefix 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
>>> print(col.Name) snr >>> print(col.getAttribute("Name")) test:snr >>> col.Name = col.Name >>> print(col.Name) snr >>> print(col.getAttribute("Name")) 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.
Attributes Summary
The "Name" attribute.
The "Type" attribute.
The "Unit" attribute.
Methods Summary
asarray()Construct a numpy array from this column.
count(value)Return the number of rows with this column equal to value.
end_tag(indent)Generate the string for the element's end tag.
getColumnsByName(elem, name)Return a list of Column elements named name under elem.
index(value)Return the smallest index of the row(s) with this column equal to value.
start_tag(indent)Generate the string for the element's start tag.
write([fileobj, indent])Recursively write an element and it's children to a file.
Attributes Documentation
- Name¶
The “Name” attribute.
- Type¶
The “Type” attribute.
- Unit¶
The “Unit” attribute.
- table_name¶
- tagName = 'Column'¶
Methods Documentation
- asarray()¶
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.
- count(value)¶
Return the number of rows with this column equal to value.
- end_tag(indent)¶
Generate the string for the element’s end tag.
- classmethod getColumnsByName(elem, name)¶
Return a list of Column elements named name under elem.
- index(value)¶
Return the smallest index of the row(s) with this column equal to value.
- start_tag(indent)¶
Generate the string for the element’s start tag.
- write(fileobj=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, indent='')¶
Recursively write an element and it’s children to a file.