-
Notifications
You must be signed in to change notification settings - Fork 53
Clarify types to allow None in indexing #674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I believe that the indexing specification allow `None` in a selection tuple, but the current typing does not specify this. I have changed the signature for `__getitem__` but did not change `__setitem__`. I am not sure where it is documented if the indexing specification applies to both equally.
Should this be backported to prior revisions? |
I guess the spec doesn't actually say anything about None as the sole index. |
Yeah it doesn't say it's allowed, so I wasn't sure if it was. Do you think the assumption was that it is allowed? I know there are some E2E tests as well, but I wasn't sure where they live, if they contain this use case. |
Tests are at https://github.com/data-apis/array-api-tests/blob/master/array_api_tests/test_array_object.py#L81, but it comes down to what is implemented in numpy.array_api doesn't allow it, and gives the error
which suggests that maybe this is intentional, because we decided to only allow sole-indices (non-tuple) when the index specifies every axis of the array. Actually in |
Oh, do you mean that if you have a 2D array, for example, you can't use non-tuple indexing? I didn't catch that from the specification. EDIT: Sorry I see you just answered that question and yes you do mean that! |
Yep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. These changes should be backported given that None
is discussed in the 2021 and 2022 revisions of the API standard. As such, the exclusion of None
from the respective type definitions was an omission.
Additionally, we need to update the type signature to allow None
as the sole index, given that x[None]
is syntactic sugar for x[(None,)]
, which is explicitly noted in the specification.
I can perform the backports and updated typing in a follow-up PR.
FWIW I don't believe
|
From a typing perspective, should there be a difference? If |
I believe that the indexing specification allows None in a selection tuple, but the current typing does not specify this. I have changed the signature for getitem but did not change setitem. I am not sure where it is documented if the indexing specification applies to both equally.