anndata.acc.GraphAcc#

class anndata.acc.GraphAcc[R: AdRef[Idx2D, AnnDataLikeMetadataOnly]](dim, k, *, ref_class, scope=None)[source]#

Bases: RefAcc[R, Idx2D, AnnDataLikeMetadataOnly, AlignedArray, InMemoryArray | ExtensionArray | Variable]

Reference accessor for arrays from graph containers (A.obsp/A.varp).

Examples

>>> from anndata.acc import A, GraphAcc
>>> assert isinstance(A.obsp["distances"], GraphAcc)
>>> A.obsp["distances"][:, "cell-1"]
A.obsp['distances'][:, 'cell-1']

Attributes

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.

dim: Literal['obs', 'var']#

Axis this accessor refers to, e.g. A.varp[k].dim == "var".

k: str#

Key this accessor refers to, e.g. A.obsp['x'].k == 'x'.

ref_class: type[R]#

Methods

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 indexed array or element from the AnnData object at idx.

Overloads:

When idx is omitted (i.e., idx is NO_IDX), return the full array one level up instead. This has the same semantics as the AdRef path but one level up: adata[A.obs] returns the full DataFrame, adata[A.obsm["pca"]] the full numpy.ndarray, and adata[A.layers] the full Mapping. The first two both have defined shape-like properties (or awkward.Array), but layers or similar do not.

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

process_idx(idx, /)[source]#
Return type:

Idx2D

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