@@ -2347,8 +2347,10 @@ def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
2347
2347
2348
2348
dpnp .check_supported_arrays_type (x )
2349
2349
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
+ )
2352
2354
2353
2355
out = dpnp .empty_like (x ) if copy else x
2354
2356
x_type = x .dtype .type
@@ -2366,15 +2368,17 @@ def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
2366
2368
)
2367
2369
max_f , min_f = _get_max_min (x .real .dtype )
2368
2370
if posinf is not None :
2369
- if not dpnp . isscalar (posinf ):
2371
+ if isinstance ( posinf , bool ) or not isinstance (posinf , ( int , float ) ):
2370
2372
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 )} "
2372
2375
)
2373
2376
max_f = posinf
2374
2377
if neginf is not None :
2375
- if not dpnp . isscalar (neginf ):
2378
+ if isinstance ( neginf , bool ) or not isinstance (neginf , ( int , float ) ):
2376
2379
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 )} "
2378
2382
)
2379
2383
min_f = neginf
2380
2384
0 commit comments