Skip to content
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

Fix optional keyword argument in take signature #644

Merged
merged 2 commits into from Jul 10, 2023

Conversation

kgryte
Copy link
Contributor

@kgryte kgryte commented Jul 5, 2023

This PR:

  • fixes the signature for take in which the default value for the axis keyword argument should be None. Without this change, the axis keyword argument is always required (as arguments must always be bound to a value), even for the one-dimensional case. This PR corrects this error in the original PR.
  • backports the change to the 2022.12 revision of the array API standard.

Ref: data-apis/array-api-compat#34

This commit fixes the function signature for `take`. Namely, when
an input array is one-dimensional, the `axis` kwarg is optional;
when the array has more than one dimension, the `axis` kwarg is
required. Unfortunately, the type signature cannot encode this
duality, and we must rely on the specification text to clarify
that the `axis` kwarg is required for arrays having ranks greater
than unity.

Ref: data-apis/array-api-compat#34
@kgryte kgryte added bug Something isn't working. topic: Indexing Array indexing. labels Jul 5, 2023
@kgryte kgryte added this to the v2023 milestone Jul 5, 2023
@asmeurer
Copy link
Member

asmeurer commented Jul 5, 2023

Looks good. I'm OK with backporting this because it makes the signature match what the text of the specification already said. We will also need to update the compat library and numpy.array_api.

@asmeurer
Copy link
Member

asmeurer commented Jul 5, 2023

And the test suite. I'm pretty sure axis being optional for 1-D isn't tested because my implementations of take would have failed.

Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

LGTM too, in it goes. Thanks @kgryte and @asmeurer.

There's already data-apis/array-api-compat#34 for the follow-up action.

@rgommers rgommers merged commit 2056a94 into data-apis:main Jul 10, 2023
1 check passed
asmeurer added a commit to asmeurer/numpy that referenced this pull request Jul 15, 2023
The array_api take() doesn't flatten the array by default, so the axis
argument must be provided for multidimensional arrays. However, it should be
optional when the input array is 1-D, which the signature previously did not
allow.

c.f. data-apis/array-api#644
@asmeurer
Copy link
Member

I made a fix for numpy.array_api at numpy/numpy#24187

@kgryte kgryte deleted the fix-take-signature branch July 15, 2023 19:00
charris pushed a commit to charris/numpy that referenced this pull request Jul 23, 2023
The array_api take() doesn't flatten the array by default, so the axis
argument must be provided for multidimensional arrays. However, it should be
optional when the input array is 1-D, which the signature previously did not
allow.

c.f. data-apis/array-api#644
asmeurer added a commit to data-apis/array-api-strict that referenced this pull request Jan 22, 2024
The array_api take() doesn't flatten the array by default, so the axis
argument must be provided for multidimensional arrays. However, it should be
optional when the input array is 1-D, which the signature previously did not
allow.

c.f. data-apis/array-api#644

Original NumPy Commit: 37ba69c7b7404e4ae67ef2e4db9584852baa963a
asmeurer added a commit to data-apis/array-api-strict that referenced this pull request Jan 22, 2024
The array_api take() doesn't flatten the array by default, so the axis
argument must be provided for multidimensional arrays. However, it should be
optional when the input array is 1-D, which the signature previously did not
allow.

c.f. data-apis/array-api#644

Original NumPy Commit: 37ba69c7b7404e4ae67ef2e4db9584852baa963a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working. topic: Indexing Array indexing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants