property AnnCollection.convert[source]#

On the fly converters for keys of attributes and data matrix.

A function or a Mapping of functions which will be applied to the values of attributes (.X) or to specific keys of these attributes (.obs, .obsm, .layers) of subset objects. The converters are not applied to .obs and .obsm (if present) of this object, only to the attributes of subset objects. The keys of the Mapping should correspond to the attributes or keys of the attributes (hierarchically) and the values should be functions used for conversion.


    # densify .X
    "X": lambda a: a.toarray() if issparse(a) else a,
    # change dtype for all keys of .obsm
    "obsm": lambda a: np.asarray(a, dtype="float32"),
    # change type only for one key of .obs
    "obs": dict(key1=lambda c: c.astype(str)),