Skip to content

Test that nonzero on zero-dimensional array raises an exception. #222

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

Merged
merged 2 commits into from
Dec 7, 2023

Conversation

jakevdp
Copy link
Contributor

@jakevdp jakevdp commented Dec 6, 2023

This is required by the spec. From https://data-apis.org/array-api/2022.12/API_specification/generated/array_api.nonzero.html:

Parameters
x (array) – input array. Must have a positive rank. If x is zero-dimensional, the function must raise an exception.

I made this a separate test so that implementations can mark it to skip if desired (this currently raises a DeprecationWarning in NumPy, but will error in a future release).

@jakevdp jakevdp changed the title Test than nonzero on zero-dimensional array raises an exception. Test that nonzero on zero-dimensional array raises an exception. Dec 6, 2023
Copy link
Member

@honno honno left a comment

Choose a reason for hiding this comment

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

Nice catch thanks! LGTM.

Historically I've tested errors all in the same function to keep with some platonic ideal of 1 "primary test" per function, e.g.

def test_expand_dims(x, axis):
if axis < -x.ndim - 1 or axis > x.ndim:
with pytest.raises(IndexError):
xp.expand_dims(x, axis=axis)
return

which I'm not sure is worth it or that practical for either us maintaining array-api-tests or adopting libraries all the time. In any case, having a separate test makes sense here for sure.

@honno honno merged commit 5da9a19 into data-apis:master Dec 7, 2023
@jakevdp jakevdp deleted the nonzero-ndim branch December 7, 2023 13:29
@jakevdp
Copy link
Contributor Author

jakevdp commented Dec 7, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants