fix: don't call asarray on Index
objects internally
#2749
Merged
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 PR follows #2740. I've updated that PR's description for context, but let me restart the problem here!
nplike.asarray
ultimately invokes NumPy's array interface mechanisms when it acts upon anIndex
orContent
object. If we don't make this PR change, an array with placeholders that hits this codepath will lead to an exception being thrown.As outlined in #2740, we could update
nplike.asarray
to handle these types, but I'm really in favour of having our internals be strict where possible; both to do less work, but also to make it easier to reason about.So, this PR replaces any as-yet uncaught uses of
nplike.asarray(index)
withindex.data
if thenplike
is unchanged, ornplike.asarray(index.data)
if not.I haven't been exhaustive; anything that isn't being run in our test suite won't have been caught, but I'm happy enough with our coverage that those will hopefully not be too many that we can't deal with them as they come in.
I haven't added anything to the test suite to catch this. I'm slightly reluctant to e.g. add a strict-mode for our test suite that throws an exception if
Index._array_interface_
is inspected. We could do this, though, and I'd welcome @jpivarski thoughts!