Skip to content

indexing with a list of slices #10573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

indexing with a list of slices #10573

wants to merge 7 commits into from

Conversation

keewis
Copy link
Collaborator

@keewis keewis commented Jul 27, 2025

Following the discussion in #10479, this adds support for a list-of-slices container (tentatively called MultipleSlices) to most of the indexing wrapper classes. Still missing: PandasIndexingWrapper.

It didn't look like using a separate class as suggested in #10479 (comment) would be easy, and so I've decided to instead extend _index_indexer_1d to support, which turned out surprisingly easy.

I'll still have to figure out how to best test this for the indexing wrapper classes other than LazilyIndexingWrapper, and I'm not really content with the API and the code duplication I have right now. I'll refactor that soon, but for now this works:

In [5]: import xarray as xr
   ...: import numpy as np
   ...: 
   ...: var = xr.DataArray(np.arange(100), dims="x")
   ...: slice_ = xr.core.indexing.MultipleSlices(
   ...:     slice(7, 12), slice(15, 32, 2), slice(50, None, 3)
   ...: )
   ...: var.isel(x=slice_)
Out[5]: 
<xarray.DataArray (x: 31)> Size: 248B
array([ 7,  8,  9, 10, 11, 15, 17, 19, 21, 23, 25, 27, 29, 31, 50, 53, 56,
       59, 62, 65, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98])
Dimensions without coordinates: x

cc @dcherian

  • Closes indexing by a list of slices #10479
  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

indexing by a list of slices
1 participant