Registry Mirror
Skip to content

Conversation

@lowgame

@lowgame lowgame commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Description

RangeIndex.linspace(..., num=-1) currently creates a RangeIndex whose declared dimension size is -1, while its materialized coordinate is empty. This leaves the index internally inconsistent and later causes coordinate validation failures.

The constructor did not validate num before passing it to RangeCoordinateTransform. This change rejects negative values with the same ValueError behavior as numpy.linspace, adds a focused regression test, and documents the bug fix.

Reproduction before the production fix:

uv run pytest xarray/tests/test_range_index.py::test_range_index_linspace_negative_num -q
1 failed (DID NOT RAISE ValueError)

Validation after the fix:

uv run pytest xarray/tests/test_range_index.py xarray/tests/test_coordinate_transform.py -q
48 passed in 2.52s

uv run pre-commit run --files xarray/indexes/range_index.py xarray/tests/test_range_index.py doc/whats-new.rst
All applicable hooks passed

Checklist

  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst (not applicable; no new API)

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.
      Tools: OpenAI Codex

@dcherian
dcherian enabled auto-merge (squash) October 7, 2026 01:23
@dcherian
dcherian merged commit 4b0ab62 into pydata:main Oct 7, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants