@@ -771,8 +771,6 @@ def _init_as_view(self, adata_ref, oidx, vidx):
771
771
self ._varm = ArrayView (adata_ref .varm [vidx_normalized ], view_args = (self , 'varm' ))
772
772
# hackish solution here, no copy should be necessary
773
773
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' ))
776
774
# fix _n_obs, _n_vars
777
775
if isinstance (oidx , slice ):
778
776
self ._n_obs = len (self ._obs .index )
@@ -786,6 +784,9 @@ def _init_as_view(self, adata_ref, oidx, vidx):
786
784
self ._n_vars = 1
787
785
else :
788
786
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' ))
789
790
# set data
790
791
if self .isbacked : self ._X = None
791
792
else : self ._init_X_as_view ()
@@ -1255,7 +1256,7 @@ def _slice_uns_sparse_matrices_inplace(self, uns, oidx):
1255
1256
oidx .start is None and oidx .step is None and oidx .stop is None ):
1256
1257
for k , v in uns .items ():
1257
1258
if isinstance (v , sparse .spmatrix ) and v .shape == (
1258
- self ._n_obs , self ._n_obs ):
1259
+ self .n_obs , self .n_obs ):
1259
1260
uns [k ] = v .tocsc ()[:, obs ].tocsr ()[oidx , :]
1260
1261
1261
1262
def _inplace_subset_var (self , index ):
0 commit comments