Skip to content

Conversation

@sadielbartholomew
Copy link
Member

Close #377. Also added an equivalent test for __getitem__ which passed to begin with, for completeness.

@sadielbartholomew sadielbartholomew self-assigned this Jan 12, 2026
@sadielbartholomew sadielbartholomew added the enhancement New feature or request label Jan 12, 2026
@sadielbartholomew
Copy link
Member Author

(Resolved a trivial changelog conflict.)

Copy link
Contributor

@davidhassell davidhassell left a comment

Choose a reason for hiding this comment

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

Nicely crafted. A bit of logic needs adding for -ve integers, and as a result the tests extended, but that's all. I think we should marks it with the NEXTVERSION milestone :)

@sadielbartholomew
Copy link
Member Author

Thanks for your prompt review @davidhassell. I believe I have addressed all feedback, except:

I think we should marks it with the NEXTVERSION milestone

I am not sure where you mean to put that - I can't think of a good place in this context?

@davidhassell
Copy link
Contributor

I think we should marks it with the NEXTVERSION milestone

It's on the RHS, a bit below where we set "label"

@sadielbartholomew
Copy link
Member Author

sadielbartholomew commented Jan 14, 2026

I think we should marks it with the NEXTVERSION milestone

Oh 🤦🏻‍♀️ I now realise you mean the PR! I thought you were meaning on the code as a versionadded or similar. Sure, will set that as the milestone now.

@sadielbartholomew sadielbartholomew added this to the NEXTVERSION milestone Jan 14, 2026
)

if keepdims:
# Convert an integral index to a slice
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need some indentation here?

Copy link
Contributor

Choose a reason for hiding this comment

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

(my fault for not including it in my last suggestion!)

Copy link
Member Author

Choose a reason for hiding this comment

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

AH - I made a comment about this on the thread and now I don't see it. Not sure why it's disappeared!

Copy link
Member Author

Choose a reason for hiding this comment

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

OK after checking my tabs said comment is gone with no trace - did I just imagine/dream posting it?

What I said was (in said dream, or otherwise) is that there is an elif hasattr(index, "to_dask_array"): following the original if keepdims and isinstance(index, Integral): which means that converting to having the top-level if isinstance(index, Integral): actually complicates the flow - we'd need further somewhat contrived checking afterwards to get the equivalent. So actually I am not sure it's a good idea.

That said, no need to actually call isinstance twice - so I suggest we store that in a variable to use each time but use the original conditional structure. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

GitHub having a moment ...

Thanks for spotting this. I think what you say is worthwhile. It may seem like overkill (how long does an isinstance really take?), but this is library code, and parse_indices gets call called a lot.

Copy link
Member Author

Choose a reason for hiding this comment

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

No not overkill, you made a very good point about the duplication - but I should effectively revert the original suggestion to keep the conditionals simple given that elif, whilst getting rid of the second isinstance call. Will do that now if you're happy...

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor

@davidhassell davidhassell left a comment

Choose a reason for hiding this comment

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

+1

@sadielbartholomew sadielbartholomew merged commit e17362c into NCAS-CMS:main Jan 15, 2026
@sadielbartholomew sadielbartholomew deleted the out-of-range-indexing branch January 15, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Silent 'failure' of __setitem__ with out-of-range indices

2 participants