Skip to content

Commit ff88e0c

Browse files
authored
Merge pull request numpy#27518 from eendebakpt/nonzero_test_different_types
TST: Add tests for np.nonzero with different input types
2 parents 0f4a9a5 + 3430c11 commit ff88e0c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

numpy/_core/tests/test_numeric.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,23 @@ def test_sparse(self):
17101710
assert_equal(np.nonzero(c)[0],
17111711
np.concatenate((np.arange(10 + i, 20 + i), [20 + i*2])))
17121712

1713+
@pytest.mark.parametrize('dtype', [np.float32, np.float64])
1714+
def test_nonzero_float_dtypes(self, dtype):
1715+
rng = np.random.default_rng(seed=10)
1716+
x = ((2**33)*rng.normal(size=100)).astype(dtype)
1717+
x[rng.choice(50, size=100)] = 0
1718+
idxs = np.nonzero(x)[0]
1719+
assert_equal(np.array_equal(np.where(x != 0)[0], idxs), True)
1720+
1721+
@pytest.mark.parametrize('dtype', [bool, np.int8, np.int16, np.int32, np.int64,
1722+
np.uint8, np.uint16, np.uint32, np.uint64])
1723+
def test_nonzero_integer_dtypes(self, dtype):
1724+
rng = np.random.default_rng(seed=10)
1725+
x = rng.integers(0, 255, size=100).astype(dtype)
1726+
x[rng.choice(50, size=100)] = 0
1727+
idxs = np.nonzero(x)[0]
1728+
assert_equal(np.array_equal(np.where(x != 0)[0], idxs), True)
1729+
17131730
def test_return_type(self):
17141731
class C(np.ndarray):
17151732
pass

0 commit comments

Comments
 (0)