@@ -424,57 +424,14 @@ def maybe_promote(dtype, fill_value=np.nan):
424
424
if issubclass (dtype .type , np .bool_ ):
425
425
dtype = np .dtype (np .object_ )
426
426
elif issubclass (dtype .type , np .integer ):
427
- # upcast to prevent overflow
428
- mst = np .min_scalar_type (fill_value )
429
- if mst > dtype :
430
- # np.dtype ordering considers:
431
- # int[n] < int[2*n]
432
- # uint[n] < uint[2*n]
433
- # u?int[n] < object_
434
- dtype = mst
435
-
436
- elif np .can_cast (fill_value , dtype ):
437
- pass
438
-
439
- elif dtype .kind == "u" and mst .kind == "i" :
427
+ if not np .can_cast (fill_value , dtype ):
428
+ # upcast to prevent overflow
429
+ mst = np .min_scalar_type (fill_value )
440
430
dtype = np .promote_types (dtype , mst )
441
431
if dtype .kind == "f" :
442
432
# Case where we disagree with numpy
443
433
dtype = np .dtype (np .object_ )
444
434
445
- elif dtype .kind == "i" and mst .kind == "u" :
446
-
447
- if fill_value > np .iinfo (np .int64 ).max :
448
- # object is the only way to represent fill_value and keep
449
- # the range allowed by the given dtype
450
- dtype = np .dtype (np .object_ )
451
-
452
- elif mst .itemsize < dtype .itemsize :
453
- pass
454
-
455
- elif dtype .itemsize == mst .itemsize :
456
- # We never cast signed to unsigned because that loses
457
- # parts of the original range, so find the smallest signed
458
- # integer that can hold all of `mst`.
459
- ndt = {
460
- np .int64 : np .object_ ,
461
- np .int32 : np .int64 ,
462
- np .int16 : np .int32 ,
463
- np .int8 : np .int16 ,
464
- }[dtype .type ]
465
- dtype = np .dtype (ndt )
466
-
467
- else :
468
- # bump to signed integer dtype that holds all of `mst` range
469
- # Note: we have to use itemsize because some (windows)
470
- # builds don't satisfiy e.g. np.uint32 == np.uint32
471
- ndt = {
472
- 4 : np .int64 ,
473
- 2 : np .int32 ,
474
- 1 : np .int16 , # TODO: Test for this case
475
- }[mst .itemsize ]
476
- dtype = np .dtype (ndt )
477
-
478
435
fill_value = dtype .type (fill_value )
479
436
480
437
elif issubclass (dtype .type , np .floating ):
0 commit comments