@@ -2290,15 +2290,15 @@ def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
2290
2290
Whether to create a copy of `x` (``True``) or to replace values
2291
2291
in-place (``False``). The in-place operation only occurs if casting to
2292
2292
an array does not require a copy.
2293
- nan : {int, float}, optional
2293
+ nan : {int, float, bool }, optional
2294
2294
Value to be used to fill ``NaN`` values.
2295
2295
Default: ``0.0``.
2296
- posinf : {int, float, None}, optional
2296
+ posinf : {int, float, bool, None}, optional
2297
2297
Value to be used to fill positive infinity values. If no value is
2298
2298
passed then positive infinity values will be replaced with a very
2299
2299
large number.
2300
2300
Default: ``None``.
2301
- neginf : {int, float, None} optional
2301
+ neginf : {int, float, bool, None} optional
2302
2302
Value to be used to fill negative infinity values. If no value is
2303
2303
passed then negative infinity values will be replaced with a very
2304
2304
small (or negative) number.
@@ -2347,9 +2347,12 @@ 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 isinstance (nan , bool ) or not isinstance (nan , (int , float )):
2350
+ # Python boolean is a subtype of an integer
2351
+ # so additional check for bool is not needed.
2352
+ if not isinstance (nan , (int , float )):
2351
2353
raise TypeError (
2352
- f"nan must be a scalar of an integer or float, but got { type (nan )} "
2354
+ "nan must be a scalar of an integer, float, bool, "
2355
+ f"but got { type (nan )} "
2353
2356
)
2354
2357
2355
2358
out = dpnp .empty_like (x ) if copy else x
@@ -2368,17 +2371,17 @@ def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
2368
2371
)
2369
2372
max_f , min_f = _get_max_min (x .real .dtype )
2370
2373
if posinf is not None :
2371
- if isinstance ( posinf , bool ) or not isinstance (posinf , (int , float )):
2374
+ if not isinstance (posinf , (int , float )):
2372
2375
raise TypeError (
2373
- "posinf must be a scalar of an integer or float, or None , "
2374
- f"but got { type (posinf )} "
2376
+ "posinf must be a scalar of an integer, float, bool , "
2377
+ f"or be None, but got { type (posinf )} "
2375
2378
)
2376
2379
max_f = posinf
2377
2380
if neginf is not None :
2378
- if isinstance ( neginf , bool ) or not isinstance (neginf , (int , float )):
2381
+ if not isinstance (neginf , (int , float )):
2379
2382
raise TypeError (
2380
- "neginf must be a scalar of an integer or float, or None , "
2381
- f"but got { type (neginf )} "
2383
+ "neginf must be a scalar of an integer, float, bool , "
2384
+ f"or be None, but got { type (neginf )} "
2382
2385
)
2383
2386
min_f = neginf
2384
2387
0 commit comments