Registry Mirror
Skip to content

Conversation

@avalentino

@avalentino avalentino commented Dec 22, 2025 •

Copy link
Copy Markdown
Contributor

@keewis keewis changed the title Support nevative step in normalize_indexer Support negative step in normalize_indexer Dec 22, 2025
@avalentino

avalentino commented Dec 22, 2025 •

Copy link
Copy Markdown
Contributor Author

The failure seems to be unrelated
Unfortunately this patch seems not to fix the rioxarray issue.

Edited: After testing more carefully I can confirm that the patch actually fixes #11000.

@jsignell jsignell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good @avalentino sorry it took a while for anyone to review. It slipped through the cracks around the holidays. Do you want to add a section to what's new?

@jsignell jsignell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avalentino

Copy link
Copy Markdown
Contributor Author

Hi @jsignell , should be fixed now.

Comment thread xarray/core/indexing.py
>>> _expand_slice(slice(0, -1), 10)
array([0, 1, 2, 3, 4, 5, 6, 7, 8])
"""
sl = normalize_slice(slice_, size)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why aren't we using normalize_slice anymore?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically this is just using the old version of the function. To me it looks like the alternative would be to catch stop=None and set it to -1 before passing it into np.arange. But slice(*slice_.indices(size)) already returns stop=-1 anyways so 🤷

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have two options: add an option to normalize_slice that allows switching between targeting range or slice (we might need to rename the function then), or just use slice.indices directly. The latter would mean that we'd do this here:

    start, stop, step = slice_.indices(size)
    return np.arange(start, stop, step)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the second option.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have implemented what @keewis suggestd

Comment thread xarray/core/indexing.py Resolved

@jsignell jsignell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Just a suggestion about the docstring.

Comment thread doc/whats-new.rst Resolved
@jsignell
jsignell enabled auto-merge (squash) February 4, 2026 21:56
@jsignell
jsignell merged commit 21153ed into pydata:main Feb 4, 2026
@welcome

welcome Bot commented Feb 4, 2026

Copy link
Copy Markdown

Congratulations on completing your first pull request! Welcome to Xarray! We are proud of you, and hope to see you again! celebration gif

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.

BUG: normalize_indexer breaks _decompose_slice

4 participants