anndata.experimental.backed.Dataset2D#
- class anndata.experimental.backed.Dataset2D(ds)[source]#
Bases:
Mapping[Hashable, XDataArray | Dataset2D]A wrapper class meant to enable working with lazy dataframe data according to
AnnData’s internal API. This class ensures that “dataframe-invariants” are respected, namely that there is only one 1d dim and coord with the same name i.e., like apandas.DataFrame.You should not have to initiate this class yourself. Setting an
xarray.Datasetinto a relevant part of theAnnDataobject will attempt to wrap that object in this object, trying to enforce the “dataframe-invariants.”Because xarray requires
xarray.Dataset.coordsto be in-memory, this class provides handling for an out-of-memory index viatrue_index. This feature is helpful for loading remote data faster where the index itself may not be initially useful for constructing the object e.g., cell ids.Attributes
- columns#
AnnDatainternally looks forcolumnsso this ensures usability- Returns:
pandas.Indexthat represents the “columns.”
- ds#
The underlying
xarray.Dataset.
- dtypes#
Return a Mapping with the dtypes of the variables in the Dataset2D.
- iloc#
AnnDatainternally looks forilocso this ensures usability.- Returns:
Handler class for doing the iloc-style indexing using
isel().
- index#
A
pandas.Indexobject corresponding toanndata.experimental.backed.Dataset2D.index_dim.AnnDatainternally looks forindexso this ensures usability.- Returns:
The index of the of the dataframe as resolved from
coords.
- index_dim#
The underlying computational index i.e., the lone coordinate dimension.
- is_backed#
Check whether or not the object is backed, used to indicate if there are any in-memory objects. Must be externally set, defaults false.
- shape#
AnnDatainternally looks forshapeso this ensures usability.- Returns:
The (2D) shape of the dataframe resolved from
sizes.
- true_index#
true_xr_indexas apandas.Index.
- true_index_dim#
Key of the “true” index.
Because xarray loads its coordinates/indexes in memory, we allow for signaling that a given variable, which is not a coordinate, is the “true” index.
For example, the true index may be cell names but loading these over an internet connection may not be desirable or necessary for most use cases such as getting a quick preview of the columns or loading only one column that isn’t the index.
This property is the key of said variable. The default is
index_dimif this variable has not been set.
- xr_index#
The coordinate of
anndata.experimental.backed.Dataset2D.index_dim
Methods
- __getitem__(key)[source]#
Get a column or a subset of columns.
- Overloads:
key (
Collection[Hashable]) →Dataset2D
- Parameters:
- key
Mapping[Any,Any] |Hashable|Iterable[Hashable] A column name returns that column as an
xarray.DataArray, a collection of column names returns aDataset2Dwith those columns. Seexarray.Dataset.__getitem__()for all supported keys.
- key
- __setitem__(key, value)[source]#
Setting can only be performed when the incoming value is “standalone” like
numpy.ndarrayto mimic pandas. One can also use the tuple setting style likeds["foo"] = (ds.index_dim, value)to set the value, although the index name must match. Similarly, one can use thexarray.DataArraybut it must have the same (one and only one) dim name/coord name asindex_dim.For supported setter values see
xarray.Dataset.__setitem__().
- copy(data=None, *, deep=False)[source]#
Return a copy of the Dataset2D object. See
xarray.Dataset.copy()for more information.- Return type:
- equals(b)[source]#
Thin wrapper around
xarray.Dataset.equals()- Return type:
- reindex(index=None, axis=0, fill_value=nan)[source]#
Reindex the current object against a new index.
- Parameters:
- Return type:
- Returns:
Reindexed dataset.
- to_memory(*, copy=False)[source]#
Converts to
pandas.DataFrame. The index of the dataframe comes fromtrue_index_dimif it differs fromindex_dim.- Parameters:
- copy
bool Unused argument
- copy
- Return type:
- Returns:
pandas.DataFramewith index set accordingly.