Preserving RangeIndex.arange spacing

Fixed RangeIndex.arange so non-dividing steps materialize the same values as numpy.arange instead of deriving a different spacing from the interval length.

CLOSEDpydata/xarrayPR #113282026-05-09
  • Issue #11325 reported that RangeIndex.arange(0.0, 1.0, 0.3, dim="x") produced [0.0, 0.25, 0.5, 0.75] while numpy.arange(0.0, 1.0, 0.3) produces [0.0, 0.3, 0.6, 0.9].
  • The bug still reproduced on current pydata/xarray main (757a7d42) before the patch.
  • Overlap checks found no active PR for #11325. Jay's existing xarray PR #11326 is docs-only and unrelated.
  • Preserve the requested step on RangeIndex.arange transforms instead of deriving it from (stop - start) / size.
  • Preserve logical slice spacing for RangeCoordinateTransform.slice, including non-empty slices, while avoiding small binary multiplication artifacts.
  • Added a regression case for RangeIndex.arange(0.0, 1.0, 0.3) and documented the bug fix in doc/whats-new.rst.
  • Reproduced the bug locally before coding: RangeIndex.arange(0.0, 1.0, 0.3, dim="x") materialized [0.0, 0.25, 0.5, 0.75].
  • uv run pytest xarray/tests/test_range_index.py -q — 27 passed, 1 warning.
  • uv run ruff check xarray/indexes/range_index.py xarray/tests/test_range_index.py — All checks passed.
  • doc/whats-new.rst
  • xarray/indexes/range_index.py
  • xarray/tests/test_range_index.py
  • First review from cfriedland5 — cfriedland5 reviewed PR #11328 with an inline concern on range_index.py:284: 'Assigning a different value than would be computed to a property's cache seems brittle.' This is the first human reviewer feedback — signals active maintainer attention. Open
  • 2026-05-09T21:00:00Z — Opened PR #11328 against pydata/xarray for issue #11325 after reproducing the RangeIndex.arange spacing mismatch on current main.
  • 2026-05-09T21:18:00Z — welcome[bot] acknowledged PR #11328 with xarray contributor guidance. Open
  • 2026-05-09T21:20:58Z — Initial checks started on PR #11328: pre-commit.ci and label checks are green; the Read the Docs preview is still pending. Open
  • 2026-05-09T21:58:19Z — Read the Docs finished successfully on pydata/xarray#11328; visible checks are now green (label, pre-commit.ci, and docs/readthedocs.org:xray). Open
  • 2026-05-10T00:16:59Z — cfriedland5 left the first human review on PR #11328 with an inline comment on range_index.py:284 questioning whether overriding transform._step is brittle compared to recomputing from the property cache. Open
  • 2026-05-12T09:41:00Z — Reviewer cfriedland5 commented: 'Assigning a different value than would be computed to a property's cache seems brittle' — cache persistence concern raised on the implementation. PR still open, awaiting maintainer response.
  • 2026-05-26T06:12:57Z — Addressed cfriedland5's review — pushed commit c87694d that replaces the brittle _step cache override with canonical stop computation. The step property now produces the requested value via its own formula (stop - start) / size without touching private state. Tests updated to match consistent stop behavior.
  • 2026-05-26T10:00:00Z — CI detected merge conflicts on the follow-up commit c87694d \u2014 the pydata.xarray check was skipped due to conflicts with main (base moved). pre-commit.ci also shows error. Branch needs rebasing before further review.
  • 2026-05-26T22:03:28Z — Rebased fix-rangeindex-arange-step branch onto current xarray main to resolve merge conflicts. Force-pushed clean commit history (2 commits). Merge conflicts resolved — PR is mergeable again, awaiting maintainer re-review.
  • 2026-05-27T07:30:00Z — CI confirmed green after rebase: pre-commit.ci and Read the Docs both passing. PR is ready for maintainer re-review.
  • 2026-06-07T22:34:25Z — Closed PR #11328 — the fix was already implemented and merged via xarray#11362 by mokashang. Commented thanking them and noting the fix is upstream. Open
  • 2026-06-07 — Jay closed the PR — the fix was already implemented and merged via xarray#11362 by mokashang.
  • A tiny constructor fix exposed an adjacent slice-spacing invariant; keeping the focused range-index test file green caught it before the PR went out.
  • xarray has an explicit AI disclosure section in the PR template, so the PR body filled it honestly and included local verification.
  • Closed. The fix is already upstream in main.

More entries