ENH: allow numpy integer scalars to index fileslice #903
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.
This is done by allowing 0-dimensional numpy integer arrays to return true in the
is_fancy
function.Tests are added to show identical behaviour as normal integers for canonical_slicers and fileslice (the two places where
is_fancy
is used).The reason for this is that I often find myself trying to index like
dataobj[..., idx]
, whereidx
is an numpy integer scalar, and getting afancy indexing is not allowed
error. This can be easily fixed by casting the numpy integer to a python one likedataobj[..., int(idx)]
. However, as the indexing rules are identical for scalar numpy integers and python built-in integers (except that the former returns a copy, while the latter returns a view), I feel this casting should not be necessary.This is distinct from #531 as this focusses just on 0-dimensional scalars and still disallows indexing with 1- or higher dimensional arrays.