ehrdata.io.write_h5ad

Contents

ehrdata.io.write_h5ad#

ehrdata.io.write_h5ad(edata, filename, *, compression=None, compression_opts=None)#

Write EHRData objects to an hdf5 file.

It is possible to either write an EHRData object to an .h5ad or a compressed .gzip or lzf file. To write to an h5ad file, X and layers cannot be written as object dtype. If any of these fields is of object dtype, it this function will attempt to cast it to a numeric dtype; if this fails, the field will be casted to a string dtype.

Parameters:
filename str | Path

Name of the output file, can also be prefixed with relative or absolute path to save the file to.

edata EHRData

Central data object.

compression Literal['gzip', 'lzf'] | None (default: None)

Optional file compression. Setting compression to ‘gzip’ can save disk space but will slow down writing and subsequent reading.

compression_opts int | None (default: None)

See http://docs.h5py.org/en/latest/high/dataset.html.

Return type:

None

Examples

>>> import ehrdata as ed
>>> edata = ed.dt.mimic_2()
>>> ed.io.write_h5ad("mimic_2.h5ad", edata)