Skip to content

Commit

Permalink
(chore): bring in last changes from read_backed branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ilan-gold committed Jul 30, 2023
1 parent 79c59dd commit e145284
Showing 1 changed file with 32 additions and 113 deletions.
145 changes: 32 additions & 113 deletions anndata/_core/anndata_base.py
Original file line number Diff line number Diff line change
@@ -1,179 +1,98 @@
from abc import abstractmethod
from typing import Tuple
import pandas as pd

from .file_backing import AnnDataFileManager
from ..utils import DeprecationMixinMeta


class AbstractAnnData(metaclass=DeprecationMixinMeta):
def _init_as_actual(
self,
X=None,
obs=None,
var=None,
uns=None,
obsm=None,
varm=None,
varp=None,
obsp=None,
raw=None,
layers=None,
dtype=None,
shape=None,
filename=None,
filemode=None,
):
# view attributes
self._is_view = False
self._adata_ref = None
self._oidx = None
self._vidx = None
x_indices = []
if filename is not None:
self.file = AnnDataFileManager(self, filename, filemode)
else:
self.file = AnnDataFileManager(self, None)
(
X,
obs,
var,
uns,
obsm,
varm,
obsp,
varp,
layers,
raw,
x_indices,
) = self._reformat_axes_args_from_X(
X, obs, var, uns, obsm, varm, obsp, varp, layers, raw
)
self._assign_X(X, shape, dtype)

self._initialize_indices(shape, obs, var)
assert self.n_obs == self.shape[0]
assert self.n_vars == self.shape[1]
if self.X is not None:
assert self.n_obs == self.X.shape[0]
assert self.n_vars == self.X.shape[1]

self._assign_obs(obs)
self._assign_var(var)
# now we can verify if indices match!
for attr_name, x_name, idx in x_indices:
attr = getattr(self, attr_name)
if isinstance(attr.index, pd.RangeIndex):
attr.index = idx
elif not idx.equals(attr.index):
raise ValueError(f"Index of {attr_name} must match {x_name} of X.")

self._assign_uns(uns)
self._assign_obsm(obsm)
self._assign_varm(varm)
self._assign_obsp(obsp)
self._assign_varp(varp)
self._assign_layers(layers)
self._run_checks()
self._cleanup_raw_and_uns(raw, uns)

@abstractmethod
def _init_as_view(self, *args, **kwargs):
pass

@abstractmethod
def _assign_X(self, X, shape, dtype):
pass

def _reformat_axes_args_from_X(self, *args):
return args

@abstractmethod
def _initialize_indices(self, *args):
pass

@abstractmethod
def _assign_obs(self, obs):
pass

@property
@abstractmethod
def _assign_var(self, var):
def X(self):
pass

@X.setter
@abstractmethod
def _assign_layers(self, layers):
def X(self, X):
pass

@property
@abstractmethod
def _assign_uns(self, uns):
def obs(self):
pass

@obs.setter
@abstractmethod
def _assign_obsm(self, obsm):
def obs(self, obs):
pass

@property
@abstractmethod
def _assign_varm(self, varm):
def obsm(self):
pass

@obsm.setter
@abstractmethod
def _assign_obsp(self, obsp):
def obsm(self, obsm):
pass

@property
@abstractmethod
def _assign_varp(self, varp):
def obsp(self):
pass

@obsp.setter
@abstractmethod
def _assign_layers(self, layers):
def obsp(self, obsp):
pass

@property
@abstractmethod
def _run_checks(self, *args):
def var(self):
pass

@var.setter
@abstractmethod
def _cleanup(self, *args):
def var(self, var):
pass

@property
@abstractmethod
def X(self):
def uns(self):
pass

@property
@uns.setter
@abstractmethod
def obs(self):
def uns(self, uns):
pass

@property
@abstractmethod
def obsm(self):
def varm(self):
pass

@property
@varm.setter
@abstractmethod
def obsp(self):
def varm(self, varm):
pass

@property
@abstractmethod
def var(self):
def varp(self):
pass

@property
@varp.setter
@abstractmethod
def uns(self):
def varp(self, varp):
pass

@property
@abstractmethod
def varm(self):
def raw(self):
pass

@property
@raw.setter
@abstractmethod
def varp(self):
def raw(self, raw):
pass

@property
Expand Down

0 comments on commit e145284

Please sign in to comment.