anndata.acc.ItemAcc#

class anndata.acc.ItemAcc[R: AdRef](path, *, ref_class, scope=None)[source]#

Bases: ScopeAcc[R, AnnDataLikeMetadataOnly]

Accessor for (possibly nested) items in .uns (A.uns[k]).

Indexing it with a key descends further into the item (treating it as a mapping). It can’t create references itself, as items in .uns aren’t aligned to any dimension, but it can be cast into a type with arrays inside (.AD, .DF).

Examples

>>> from anndata.acc import A, ItemAcc
>>> assert isinstance(A.uns["foo"], ItemAcc)
>>> A.uns["foo"]["bar"]
A.uns['foo']['bar']
>>> A.uns["baz"].AD.obs["x"]
A.uns['baz'].AD.obs['x']
>>> A.uns["df"].DF["col"]
A.uns['df'].DF['col']

Attributes

property AD: AdAcc[R][source]#

Treat the item as a nested AnnData object, e.g. A.uns['a'].AD.obs['x'].

property DF: DFAcc[R][source]#

Treat the item as a data frame, e.g. A.uns['a'].DF['col'].

scope: ScopeAcc | None = None#

Accessor for the element whose .AD cast this accessor is in, e.g. A.uns['a'] for A.uns['a'].AD.obsm['x'].DF.

If None, this accessor refers into the object passed to get()/set()/isin() itself.

path: tuple[str, ...]#

Keys leading to the item, e.g. A.uns['a']['b'].path == ('a', 'b').

ref_class: type[R]#

Methods

__getitem__(k, /)[source]#

Get an accessor for an item nested in this one, e.g. A.uns['a']['b'].

Parameters:
k str

The key of the nested item.

Return type:

Self

dims(idx, /)[source]#

Get along which dimensions the referenced array is.

Return type:

Collection[Literal['obs', 'var']]

get(data, idx=NO_IDX, /)[source]#

Get the referenced element.

Return type:

object

idx_repr(idx)[source]#

Get a string representation of the index.

Return type:

str

isin(data, idx=None)[source]#

Check if the referenced array is in the AnnData object.

Returns False if scope (or frame_acc) isn’t in data or doesn’t have the type this accessor casts it to (.AD/.DF).

The base implementation only checks scope. Subclasses should return False if super().isin(data, idx) does, so container() won’t fail afterwards.

Return type:

bool

set(data, idx, value, /)[source]#

Set the indexed array or element in the AnnData object at idx.

When idx is NO_IDX, replace the full element one level up (see get()), otherwise assign into the existing element in-place.

Return type:

None