@@ -405,11 +405,8 @@ def maybe_promote(dtype, fill_value=np.nan):
405
405
dtype = np .min_scalar_type (fill_value )
406
406
407
407
elif dtype .kind == "c" :
408
- if not np .can_cast (fill_value , dtype ):
409
- if np .can_cast (fill_value , np .dtype ("c16" )):
410
- dtype = np .dtype (np .complex128 )
411
- else :
412
- dtype = np .dtype (np .object_ )
408
+ mst = np .min_scalar_type (fill_value )
409
+ dtype = np .promote_types (dtype , mst )
413
410
414
411
if dtype .kind == "c" and not np .isnan (fill_value ):
415
412
fill_value = dtype .type (fill_value )
@@ -447,16 +444,8 @@ def maybe_promote(dtype, fill_value=np.nan):
447
444
if issubclass (dtype .type , np .bool_ ):
448
445
dtype = np .dtype (np .object_ )
449
446
elif issubclass (dtype .type , (np .integer , np .floating )):
450
- c8 = np .dtype (np .complex64 )
451
- info = np .finfo (dtype ) if dtype .kind == "f" else np .iinfo (dtype )
452
- if (
453
- np .can_cast (fill_value , c8 )
454
- and np .can_cast (info .min , c8 )
455
- and np .can_cast (info .max , c8 )
456
- ):
457
- dtype = np .dtype (np .complex64 )
458
- else :
459
- dtype = np .dtype (np .complex128 )
447
+ mst = np .min_scalar_type (fill_value )
448
+ dtype = np .promote_types (dtype , mst )
460
449
461
450
elif dtype .kind == "c" :
462
451
mst = np .min_scalar_type (fill_value )
0 commit comments