pydata / pydata/xarray

Support label-based slicing in RangeIndex

Open
#10,533 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-indexing
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

What happened?
import xarray as xr

idx1 = xr.indexes.RangeIndex.arange(0.0, 1000.0, 1e-9, dim="x")
ds1 = xr.Dataset(coords=xr.Coordinates.from_xindex(idx1))
ds1.sel(x=slice(1, 2))

raises

ValueError: RangeIndex only supports selection with method='nearest'

I think this should work

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with xarray.indexes.RangeIndex.arange and ds1.sel(x=slice(1, 2)), then trace the RangeIndex selection path. Check how selection handles method='nearest' and determine where label-based slices are rejected. Done means the shown slice selection succeeds without the current ValueError, with coverage for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.