anndata.acc.DFAcc#

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

Bases: RefAcc[R, str | None, AnnDataLikeMetadataOnly, DataFrame | Dataset2D, InMemoryArray | ExtensionArray | Variable]

Reference accessor for columns of a data frame in an AnnData object.

Created by casting another accessor to a data frame (.DF), which becomes its frame_acc. MetaAcc (A.obs/A.var) is a subclass.

Examples

>>> from anndata.acc import A, DFAcc
>>> assert isinstance(A.obsm["df"].DF, DFAcc)
>>> A.obsm["df"].DF["col"]
A.obsm['df'].DF['col']
>>> A.uns["df"].DF.index
A.uns['df'].DF.index

Attributes

frame_acc: RefAcc | None = None[source]#

Accessor for the data frame this .DF cast refers into, e.g. A.obsm['df'] for A.obsm['df'].DF.

property index: R[source]#

Index AdRef, e.g. A.obs.index or A.uns['df'].DF.index.

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.

ref_class: type[R]#

Methods

dims(k, /)[source]#

Get along which dimensions the referenced array is.

Return type:

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

frame(data, /)[source]#

Get the data frame this accessor refers to.

get(), set(), and isin() use this, so subclasses only need to override this to refer to another frame (e.g. MetaAcc returns .obs/.var of container()).

Raises:

TypeError – If the element frame_acc refers to isn’t a data frame.

Return type:

DataFrame | Dataset2D

get(data, k=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(k)[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(k, /)[source]#
Return type:

str | None

set(data, k, 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