Skip to content

Commit 3d6b825

Browse files
Add type check for nan, posinf and neginf
1 parent c3aa8ad commit 3d6b825

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

dpnp/dpnp_iface_mathematical.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,8 +2347,10 @@ def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
23472347

23482348
dpnp.check_supported_arrays_type(x)
23492349

2350-
if not dpnp.isscalar(nan):
2351-
raise TypeError(f"nan must be a scalar, but got {type(nan)}")
2350+
if isinstance(nan, bool) or not isinstance(nan, (int, float)):
2351+
raise TypeError(
2352+
f"nan must be a scalar of an integer or float, but got {type(nan)}"
2353+
)
23522354

23532355
out = dpnp.empty_like(x) if copy else x
23542356
x_type = x.dtype.type
@@ -2366,15 +2368,17 @@ def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
23662368
)
23672369
max_f, min_f = _get_max_min(x.real.dtype)
23682370
if posinf is not None:
2369-
if not dpnp.isscalar(posinf):
2371+
if isinstance(posinf, bool) or not isinstance(posinf, (int, float)):
23702372
raise TypeError(
2371-
f"posinf must be a scalar or None, but got {type(posinf)}"
2373+
"posinf must be a scalar of an integer or float, or None, "
2374+
f"but got {type(posinf)}"
23722375
)
23732376
max_f = posinf
23742377
if neginf is not None:
2375-
if not dpnp.isscalar(neginf):
2378+
if isinstance(neginf, bool) or not isinstance(neginf, (int, float)):
23762379
raise TypeError(
2377-
f"neginf must be a scalar or None, but got {type(neginf)}"
2380+
"neginf must be a scalar of an integer or float, or None, "
2381+
f"but got {type(neginf)}"
23782382
)
23792383
min_f = neginf
23802384

0 commit comments

Comments
 (0)