Skip to content

Commit 50c28f7

Browse files
committed
Improve test coverage for nan_to_num
1 parent 6038cd1 commit 50c28f7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

dpnp/tests/test_mathematical.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,27 @@ def test_errors_diff_types(self, kwarg, value):
15581558
with pytest.raises(TypeError):
15591559
dpnp.nan_to_num(ia, **{kwarg: value})
15601560

1561+
def test_error_readonly(self):
1562+
a = dpnp.array([0, 1, dpnp.nan, dpnp.inf, -dpnp.inf])
1563+
a.flags.writable = False
1564+
with pytest.raises(ValueError):
1565+
dpnp.nan_to_num(a, copy=False)
1566+
1567+
@pytest.mark.parametrize("copy", [True, False])
1568+
@pytest.mark.parametrize("dt", get_all_dtypes(no_bool=True, no_none=True))
1569+
def test_nan_to_num_strided(self, copy, dt):
1570+
n = 10
1571+
dt = numpy.dtype(dt)
1572+
np_a = numpy.arange(2 * n, dtype=dt)
1573+
dp_a = dpnp.arange(2 * n, dtype=dt)
1574+
if dt.kind in "fc":
1575+
np_a[::4] = numpy.nan
1576+
dp_a[::4] = dpnp.nan
1577+
dp_r = dpnp.nan_to_num(dp_a[::-2], copy=copy, nan=57.0)
1578+
np_r = numpy.nan_to_num(np_a[::-2], copy=copy, nan=57.0)
1579+
1580+
assert_dtype_allclose(dp_r, np_r)
1581+
15611582

15621583
class TestProd:
15631584
@pytest.mark.parametrize("axis", [None, 0, 1, -1, 2, -2, (1, 2), (0, -2)])

0 commit comments

Comments
 (0)