From ddceb4097fe920af074f61a064035c0d2ed6f681 Mon Sep 17 00:00:00 2001 From: Fabian Hausmann Date: Tue, 30 Jun 2020 16:55:23 +0200 Subject: [PATCH] Add lazy creation of obsm As mentioned in https://github.com/theislab/anndata/pull/363#issuecomment-624367298 --- anndata/_core/anndata.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/anndata/_core/anndata.py b/anndata/_core/anndata.py index 6669129ec..996045bdf 100644 --- a/anndata/_core/anndata.py +++ b/anndata/_core/anndata.py @@ -904,11 +904,15 @@ def obsm(self) -> Union[AxisArrays, AxisArraysView]: of length `n_obs`. Is sliced with `data` and `obs` but behaves otherwise like a :term:`mapping`. """ - return self._obsm + if self.is_view: + obsm = AxisArrays(self._adata_ref, 0, self._obsm) + return obsm._view(self, self.obs_names) + else: + return AxisArrays(self, 0, self._obsm) @obsm.setter def obsm(self, value): - obsm = AxisArrays(self, 0, vals=convert_to_dict(value)) + obsm = convert_to_dict(value) if self.is_view: self._init_as_actual(self.copy()) self._obsm = obsm