ehrdata.io.read_h5ad

Contents

ehrdata.io.read_h5ad#

ehrdata.io.read_h5ad(filename, *, backed=None, harmonize_missing_values=True, cast_variables_to_float=True)#

Read a hdf5 (h5ad) file into an EHRData object.

Parameters:
filename Path | str

Path to the file or directory to read.

backed Literal['r', 'r+'] | bool | None (default: None)

If ‘r’, load EHRData in backed mode instead of fully loading it into memory (memory mode). If you want to modify backed attributes of the EHRData object, you need to choose ‘r+’. Currently, backed only support updates to X. That means any changes to other slots like obs will not be written to disk in backed mode. If you would like save changes made to these slots of a backed EHRData, write them to a new file (see write_h5ad()).

harmonize_missing_values bool (default: True)

Whether to call ehrdata.harmonize_missing_values on all detected layers. Cannot be called if backed.

cast_variables_to_float bool (default: True)

For non-numeric arrays, try to cast the values for each variable to dtype np.float64. If the cast fails for the values of one variable, then the values of these variable remain unaltered. This can be helpful to recover arrays that were of dtype object when they were written to disk. Cannot be called if backed.

Return type:

EHRData

Examples

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