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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions array_api_tests/test_searching_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@ def test_argmin(x, data):
ph.assert_scalar_equals("argmin", type_=int, idx=out_idx, out=min_i, expected=expected)


@given(xps.arrays(dtype=xps.scalar_dtypes(), shape=()))
def test_nonzero_zerodim_error(x):
with pytest.raises(Exception):
xp.nonzero(x)


@pytest.mark.data_dependent_shapes
@given(xps.arrays(dtype=xps.scalar_dtypes(), shape=hh.shapes(min_side=1)))
@given(xps.arrays(dtype=xps.scalar_dtypes(), shape=hh.shapes(min_dims=1, min_side=1)))
def test_nonzero(x):
out = xp.nonzero(x)
if x.ndim == 0:
assert len(out) == 1, f"{len(out)=}, but should be 1 for 0-dimensional arrays"
else:
assert len(out) == x.ndim, f"{len(out)=}, but should be {x.ndim=}"
assert len(out) == x.ndim, f"{len(out)=}, but should be {x.ndim=}"
out_size = math.prod(out[0].shape)
for i in range(len(out)):
assert out[i].ndim == 1, f"out[{i}].ndim={x.ndim}, but should be 1"
Expand Down
3 changes: 3 additions & 0 deletions numpy-skips.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ array_api_tests/test_array_object.py::test_getitem
# missing copy arg
array_api_tests/test_signatures.py::test_func_signature[reshape]

# does not (yet) raise an exception for zero-dimensional inputs to nonzero
array_api_tests/test_searching_functions.py::test_nonzero_zerodim_error

# https://github.com/numpy/numpy/issues/21211
array_api_tests/test_special_cases.py::test_iop[__iadd__(x1_i is -0 and x2_i is -0) -> -0]
# https://github.com/numpy/numpy/issues/21213
Expand Down