to_table_type#

gwpy.io.ligolw.to_table_type(val: object, cls: type[Table], colname: str) object[source]#

Cast a value to the correct type for inclusion in a LIGO_LW table.

This method returns the input unmodified if a type mapping for colname isn’t found.

Parameters:
valobject

The input object to convert, of any type

clstype, subclass of Table

the table class to map against

colnamestr

The name of the mapping column

Returns:
objobject

The input val cast to the correct type

Examples

>>> from gwpy.io.ligolw import to_table_type as to_ligolw_type
>>> from igwn_ligolw.lsctables import SnglBurstTable
>>> x = to_ligolw_type(1.0, SnglBurstTable, 'central_freq'))
>>> print(type(x), x)
<class 'numpy.float32'> 1.0