anndata.AnnData.reduce

Contents

anndata.AnnData.reduce#

AnnData.reduce(func, *, init, order='DFS-post')[source]#

Accumulate a value starting from init by iterating over the “elems”/leaf nodes of the AnnData object.

All visits inside the user-defined func (see types.ReduceFunc()) are distinguishable via the ref_acc + elem args. Visits to {attr}`~AnnData.raw` pass ref_acc is None and isinstance(elem, Raw) to the types.ReduceFunc(). Visits to {attr}`~AnnData.uns` pass ref_acc is None and isinstance(elem, dict) to the types.ReduceFunc(). Furthermore, neither element is descended into. This behavior could change where a new ref_acc type will be available, in which case we could start descending in these cases. All other elements will have a non-None ref_acc argument indicating the path at which elem was created in the AnnData.

Parameters:
func ReduceFunc[TypeVar(T)]

The function that performs the accumulation.

init TypeVar(T)

The starting value

order Literal['DFS-pre', 'DFS-post'] (default: 'DFS-post')

How to visit the items in the reduce. “DFS-pre” indicates that parent-elements like layers, obs, and varp get visited first. “DFS-post” means they get visited afterwards. The AnnData itself is not visited.

Return type:

TypeVar(T)

Returns:

An accumulated value