mangadap.util.datatable module
Light-weight class for handling data tables using numpy record arrays.
Copyright © 2019, SDSS-IV/MaNGA Pipeline Group
- class mangadap.util.datatable.DataTable(keys, types, element_shapes=None, descr=None, shape=None)[source]
Bases:
object
A light-weight class that wraps a numpy record array.
- Parameters:
keys (
str
,list
) – Table column keys. Must be a single string or a list of strings.types (
type
,list
) – Column data type. Must be a single type or a list of types. Supported types are limited to integers and floating point values. If a single type and more than one key is provided, all columns will have the same type.element_shapes (
tuple
,list
, optional) – Shape of each column element. If None, all elements are assumed to be single values. If a list is provided, the elements of the list must be either None (for a single value) or a tuple with the shape of each element. If a single shape and more than one key is provided, all columns will have the same element shape.descr (
str
,list
, optional) – Human-readable description of each column. If None, no descriptions are available. If a list, each element must be a string or None. If not None, must provide a description or a None element for each key.shape (
int
,tuple
) – Shape of the data table to instantiate. If None,data
will be None and instantiation of the array will require a call toinit()
.
- Raises:
TypeError – Raised if any of the provided arguments or list item have an incorrect type.
ValueError – Raised if any of the provided arguments do not provide the same number of columns as determined by the column keys.
- keys
See argument list.
- Type:
list
- types
See argument list.
- Type:
list
- element_shapes
See argument list.
- Type:
list
- descr
See argument list.
- Type:
list
- data
Array with the table data.
- Type:
- _dtype
List of tuples with the data type of the record array.
- Type:
list
- append(rhs)[source]
Append the data in the provided datatable to this one.
Both objects (
self
andrhs
) must have the same derived class. This instance is directly modified.- Parameters:
rhs (
DataTable
) –The instance with the data to append. The derived class of this object must be the same as the object to which you want to append the data. I.e.:
assert isinstance(rhs, self.__class__)
- property dtype
Return the data type of the record array.
If
data
has been initialized, this is identically:self.data.dtype
- Returns:
Table data type.
- Return type:
- init(shape)[source]
(Re)Initialize
data
.Note that this always re-initializes the array, regardless of whether or not there was a pre-existing data array.
- Parameters:
shape (
tuple
) – The shape of the array to construct.
- property shape
Return the shape of the data array.
- Returns:
Returns the shape of the data array. If the
data
has not been instantiated, returns None.- Return type:
tuple
- property size
Return the size of the data array.
- Returns:
Returns the number of elements in the array. If the
data
has not been instantiated, returns 0.- Return type:
int
- to_hdu(name=None, add_dim=False)[source]
Use the data table to build an astropy.io.fits.BinTableHDU.
Todo
add_dim
shouldn’t be optional; the code should just do this always or know when it needs to.
- Parameters:
name (
str
, optional) – HDU extension name.add_dim (
bool
, optional) – Include the dimensionality of the column in the construction of the astropy.io.fits.Column.
- Returns:
FITS binary table with the data.
- Return type:
- to_rst_table(header=True, class_link=True)[source]
Construct a reStructuredText table describing the data table.
- Parameters:
header (
bool
, optional) – Include a section headerclass_link (
bool
, optional) – Include an rst-style link to the class instantiation documentation.
- Returns:
Returns a list of lines that can be written to an
*.rst
file.- Return type:
list