anndict.AdataDict.fapply#
- AdataDict.fapply(func, *, use_multithreading=True, num_workers=None, max_retries=0, catch_errors=True, return_as_adata_dict=False, **kwargs_dicts)[source]#
Applies
functo eachAnnDatainadata_dict, with error handling, retry mechanism, and the option to use either threading or sequential execution. The return behaviour is based on the return behaviour offunc.kwargscan beAny. if akwargis adictwith keys that matchadata_dict, then values are broadcast to thefunccall on the corresponding key-value ofadata_dict. Otherwise, the kwarg is directly broadcast to all calls offunc.- Parameters:
- adata_dict
AdataDict An
AdataDict.- func
callable Function to apply to each
AnnDataobject inadata_dict.- use_multithreading
bool(default:True) If True, use
ThreadPoolExecutor; if False, execute sequentially. Default is True.- num_workers
int|None(default:None) Number of worker threads to use. If
None, defaults to the number of CPUs available.- max_retries
int(default:0) Maximum number of retry attempts after the first failure. (i.e. 0 means no retries, 1 means one retry after the first failure, for a total of 2 attempts)
- catch_errors
bool(default:True) If
False, raise exceptions instead of catching errors.- return_as_adata_dict
bool(default:False) Whether to return the results as a
dict(ifFalse) orAdataDict(ifTrue).- kwargs_dicts
Any Additional keyword arguments to pass to the function.
- adata_dict
- Return type:
dict|AdataDict|None- Returns:
If all results are None: None
Otherwise: A
dictorAdataDict(based on return_as_adata_dict) containing all results offuncapplied to each AnnData
Notes
Be careful when setting
max_retries != 0. If retries are used, the same function will be called again on whatever the current data is, which may not be the original data. For example, iffunclog-transform the data, then does something that fails, the second timefuncis called, the already log-transformed data will have another log transform applied.