Skip to content

Commit

Permalink
(chore): refactor ZarrArray subset function
Browse files Browse the repository at this point in the history
  • Loading branch information
ilan-gold committed Jul 30, 2023
1 parent 703812c commit 8ce994b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions anndata/_core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,18 @@ def unpack_index(index: Index) -> Tuple[Index1D, Index1D]:


@singledispatch
def _subset(a: Union[np.ndarray, pd.DataFrame], subset_idx: Index):
def _subset(a: np.ndarray, subset_idx: Index):
# Select as combination of indexes, not coordinates
# Correcting for indexing behaviour of np.ndarray
if all(isinstance(x, cabc.Iterable) for x in subset_idx):
subset_idx = np.ix_(*subset_idx)
if isinstance(a, ZarrArray):
return a.oindex[subset_idx]
return a[subset_idx]

@_subset.register(ZarrArray)
def _subset_zarr(a: ZarrArray, subset_idx: Index):
if all(isinstance(x, cabc.Iterable) for x in subset_idx):
subset_idx = np.ix_(*subset_idx)
return a.oindex[subset_idx]

@_subset.register(DaskArray)
def _subset_dask(a: DaskArray, subset_idx: Index):
Expand Down

0 comments on commit 8ce994b

Please sign in to comment.