Conversation
dcherian
approved these changes
Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
RangeIndex.arange()could report a negative dimension size when the interval direction conflicted with the sign ofstep:The equivalent
numpy.arange(0.0, 3.0, -1.0)is empty. The negative metadata also prevented the generated coordinate from being attached to an ordinary emptyDataArray.The size calculation used
ceil((stop - start) / step)directly, so wrong-direction intervals produced a negative count. This change clamps that count to zero before normalizingstop. Regression tests cover both ascending and descending wrong-direction intervals and verify the index size, coordinate size, and emptyDataArrayintegration.Checklist
whats-new.rstapi.rst(not applicable)Test results
uv run --no-dev --with pytest --with pytest-env --with pytest-timeout --with pytest-asyncio --with 'pytest-mypy-plugins>=4.0.0' pytest xarray/tests/test_range_index.py::test_range_index_arange_empty -q— 2 failed as expected (index.sizewas-3).uv run --no-dev --with pytest --with pytest-env --with pytest-timeout --with pytest-asyncio --with 'pytest-mypy-plugins>=4.0.0' pytest xarray/tests/test_range_index.py -q— 29 passed.pytest xarray/tests/test_indexes.py xarray/tests/test_range_index.py -q— 107 passed, 2 skipped.uv run --no-dev --with pre-commit pre-commit run --files xarray/indexes/range_index.py xarray/tests/test_range_index.py doc/whats-new.rst— passed.pytest xarray -q— 6776 passed, 9998 skipped, 12 xfailed, 4 xpassed, 2 failed. Both failures reproduce unchanged on the base commit: a pandas-dependent categorical repr byte-count mismatch andNDPointIndexrequiring scipy, which was intentionally absent from this minimal environment.AI Disclosure
Tools: OpenAI Codex
Prepared by OpenAI Codex on behalf of @lowgame; the defect was reproduced before the production change, the complete diff was reviewed, and the commands above were run locally.