From 06acccbf74f861723f7910896d6e6306c2924593 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Sun, 8 Feb 2026 21:31:57 +0100 Subject: [PATCH] MAINT: remove a dead code branch from test_nonzero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The branch is checking for x.ndim == 0, while the hypothesis decorator only generates arrays of at least ndim=1: `given(hh.arrays(dtype=hh.all_dtypes, shape=hh.shapes(min_dims=1, min_side=1)))` This is consistent with the spec: https://data-apis.org/array-api/draft/API_specification/generated/array_api.nonzero.html > x (array) – input array. **Must** have one or more dimensions. > If x is zero-dimensional, the function **must** raise an exception. --- array_api_tests/test_searching_functions.py | 22 +++++++++------------ 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/array_api_tests/test_searching_functions.py b/array_api_tests/test_searching_functions.py index 26a348d1..0d603d68 100644 --- a/array_api_tests/test_searching_functions.py +++ b/array_api_tests/test_searching_functions.py @@ -180,19 +180,15 @@ def test_nonzero(x): for idx in sh.ndindex(x.shape): if x[idx] != 0: indices.append(idx) - if x.ndim == 0: - assert out_size == len( - indices - ), f"prod(out[0].shape)={out_size}, but should be {len(indices)}" - else: - for i in range(out_size): - idx = tuple(int(x[i]) for x in out) - f_idx = f"Extrapolated index (x[{i}] for x in out)={idx}" - f_element = f"x[{idx}]={x[idx]}" - assert idx in indices, f"{f_idx} results in {f_element}, a zero element" - assert ( - idx == indices[i] - ), f"{f_idx} is in the wrong position, should be {indices.index(idx)}" + + for i in range(out_size): + idx = tuple(int(x[i]) for x in out) + f_idx = f"Extrapolated index (x[{i}] for x in out)={idx}" + f_element = f"x[{idx}]={x[idx]}" + assert idx in indices, f"{f_idx} results in {f_element}, a zero element" + assert ( + idx == indices[i] + ), f"{f_idx} is in the wrong position, should be {indices.index(idx)}" except Exception as exc: ph.add_note(exc, repro_snippet) raise