Skip to content

Commit ba9b3ee

Browse files
committed
fixed bug in init of views
1 parent f3629f4 commit ba9b3ee

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

anndata/base.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,6 @@ def _init_as_view(self, adata_ref, oidx, vidx):
771771
self._varm = ArrayView(adata_ref.varm[vidx_normalized], view_args=(self, 'varm'))
772772
# hackish solution here, no copy should be necessary
773773
uns_new = self._adata_ref._uns.copy()
774-
self._slice_uns_sparse_matrices_inplace(uns_new, self._oidx)
775-
self._uns = DictView(uns_new, view_args=(self, 'uns'))
776774
# fix _n_obs, _n_vars
777775
if isinstance(oidx, slice):
778776
self._n_obs = len(self._obs.index)
@@ -786,6 +784,9 @@ def _init_as_view(self, adata_ref, oidx, vidx):
786784
self._n_vars = 1
787785
else:
788786
self._n_vars = len(vidx)
787+
# need to do the slicing after setting self._n_obs, self._n_vars
788+
self._slice_uns_sparse_matrices_inplace(uns_new, self._oidx)
789+
self._uns = DictView(uns_new, view_args=(self, 'uns'))
789790
# set data
790791
if self.isbacked: self._X = None
791792
else: self._init_X_as_view()
@@ -1255,7 +1256,7 @@ def _slice_uns_sparse_matrices_inplace(self, uns, oidx):
12551256
oidx.start is None and oidx.step is None and oidx.stop is None):
12561257
for k, v in uns.items():
12571258
if isinstance(v, sparse.spmatrix) and v.shape == (
1258-
self._n_obs, self._n_obs):
1259+
self.n_obs, self.n_obs):
12591260
uns[k] = v.tocsc()[:, obs].tocsr()[oidx, :]
12601261

12611262
def _inplace_subset_var(self, index):

0 commit comments

Comments
 (0)