5656
5757 from zarr .storage import StoreLike
5858
59- from ..compat import Index1D , XDataset
59+ from ..compat import Index1D , Index1DNorm , XDataset
6060 from ..typing import XDataType
6161 from .aligned_mapping import AxisArraysView , LayersView , PairwiseArraysView
6262 from .index import Index
@@ -197,6 +197,11 @@ class AnnData(metaclass=utils.DeprecationMixinMeta): # noqa: PLW1641
197197
198198 _accessors : ClassVar [set [str ]] = set ()
199199
200+ # view attributes
201+ _adata_ref : AnnData | None
202+ _oidx : Index1DNorm | None
203+ _vidx : Index1DNorm | None
204+
200205 @old_positionals (
201206 "obsm" ,
202207 "varm" ,
@@ -226,8 +231,8 @@ def __init__( # noqa: PLR0913
226231 asview : bool = False ,
227232 obsp : np .ndarray | Mapping [str , Sequence [Any ]] | None = None ,
228233 varp : np .ndarray | Mapping [str , Sequence [Any ]] | None = None ,
229- oidx : Index1D | None = None ,
230- vidx : Index1D | None = None ,
234+ oidx : Index1DNorm | int | np . integer | None = None ,
235+ vidx : Index1DNorm | int | np . integer | None = None ,
231236 ):
232237 # check for any multi-indices that aren’t later checked in coerce_array
233238 for attr , key in [(obs , "obs" ), (var , "var" ), (X , "X" )]:
@@ -237,6 +242,8 @@ def __init__( # noqa: PLR0913
237242 if not isinstance (X , AnnData ):
238243 msg = "`X` has to be an AnnData object."
239244 raise ValueError (msg )
245+ assert oidx is not None
246+ assert vidx is not None
240247 self ._init_as_view (X , oidx , vidx )
241248 else :
242249 self ._init_as_actual (
@@ -256,7 +263,12 @@ def __init__( # noqa: PLR0913
256263 filemode = filemode ,
257264 )
258265
259- def _init_as_view (self , adata_ref : AnnData , oidx : Index , vidx : Index ):
266+ def _init_as_view (
267+ self ,
268+ adata_ref : AnnData ,
269+ oidx : Index1DNorm | int | np .integer ,
270+ vidx : Index1DNorm | int | np .integer ,
271+ ):
260272 if adata_ref .isbacked and adata_ref .is_view :
261273 msg = (
262274 "Currently, you cannot index repeatedly into a backed AnnData, "
@@ -277,6 +289,9 @@ def _init_as_view(self, adata_ref: AnnData, oidx: Index, vidx: Index):
277289 vidx += adata_ref .n_vars * (vidx < 0 )
278290 vidx = slice (vidx , vidx + 1 , 1 )
279291 if adata_ref .is_view :
292+ assert adata_ref ._adata_ref is not None
293+ assert adata_ref ._oidx is not None
294+ assert adata_ref ._vidx is not None
280295 prev_oidx , prev_vidx = adata_ref ._oidx , adata_ref ._vidx
281296 adata_ref = adata_ref ._adata_ref
282297 oidx , vidx = _resolve_idxs ((prev_oidx , prev_vidx ), (oidx , vidx ), adata_ref )
@@ -1004,7 +1019,9 @@ def _set_backed(self, attr, value):
10041019
10051020 write_attribute (self .file ._file , attr , value )
10061021
1007- def _normalize_indices (self , index : Index | None ) -> tuple [slice , slice ]:
1022+ def _normalize_indices (
1023+ self , index : Index | None
1024+ ) -> tuple [Index1DNorm | int | np .integer , Index1DNorm | int | np .integer ]:
10081025 return _normalize_indices (index , self .obs_names , self .var_names )
10091026
10101027 # TODO: this is not quite complete...
0 commit comments