@@ -442,6 +442,49 @@ pub fn get_supertype_with_options(
442442 None => None
443443 }
444444 } ,
445+ #[ cfg( feature = "dtype-struct" ) ]
446+ ( Struct ( fields_a) , Struct ( fields_b) ) => {
447+ super_type_structs ( fields_a, fields_b)
448+ }
449+ #[ cfg( feature = "dtype-struct" ) ]
450+ ( Struct ( fields_a) , rhs) if rhs. is_primitive_numeric ( ) => {
451+ let mut new_fields = Vec :: with_capacity ( fields_a. len ( ) ) ;
452+ for a in fields_a {
453+ let st = get_supertype ( & a. dtype , rhs) ?;
454+ new_fields. push ( Field :: new ( a. name . clone ( ) , st) )
455+ }
456+ Some ( Struct ( new_fields) )
457+ }
458+ #[ cfg( feature = "dtype-decimal" ) ]
459+ ( Decimal ( p1, s1) , Decimal ( p2, s2) ) => {
460+ Some ( Decimal ( ( * p1) . max ( * p2) , ( * s1) . max ( * s2) ) )
461+ } ,
462+ #[ cfg( all( feature = "dtype-decimal" , feature = "dtype-f16" ) ) ]
463+ ( Decimal ( _, _) , Float16 ) => Some ( Float64 ) ,
464+ #[ cfg( feature = "dtype-decimal" ) ]
465+ ( Decimal ( _, _) , Float32 | Float64 | Unknown ( UnknownKind :: Float ) ) => Some ( Float64 ) ,
466+ #[ cfg( feature = "dtype-decimal" ) ]
467+ ( Decimal ( prec, scale) , dt) if dt. is_signed_integer ( ) || dt. is_unsigned_integer ( ) => {
468+ let fits = |v| { i128_to_dec128 ( v, * prec, * scale) . is_some ( ) } ;
469+ let fits_orig_prec_scale = match dt {
470+ UInt8 => fits ( u8:: MAX as i128 ) ,
471+ UInt16 => fits ( u16:: MAX as i128 ) ,
472+ UInt32 => fits ( u32:: MAX as i128 ) ,
473+ UInt64 => fits ( u64:: MAX as i128 ) ,
474+ UInt128 => false ,
475+ Int8 => fits ( i8:: MAX as i128 ) ,
476+ Int16 => fits ( i16:: MAX as i128 ) ,
477+ Int32 => fits ( i32:: MAX as i128 ) ,
478+ Int64 => fits ( i64:: MAX as i128 ) ,
479+ Int128 => false ,
480+ _ => unreachable ! ( ) ,
481+ } ;
482+ if fits_orig_prec_scale {
483+ Some ( Decimal ( * prec, * scale) )
484+ } else {
485+ Some ( Decimal ( DEC128_MAX_PREC , * scale) )
486+ }
487+ }
445488 ( dt, Unknown ( kind) ) => {
446489 match kind {
447490 UnknownKind :: Float | UnknownKind :: Int ( _) if dt. is_string ( ) => {
@@ -453,7 +496,7 @@ pub fn get_supertype_with_options(
453496 } ,
454497 // Materialize float to float
455498 UnknownKind :: Float | UnknownKind :: Int ( _) if dt. is_float ( ) => Some ( dt. clone ( ) ) ,
456- UnknownKind :: Float if dt. is_integer ( ) | dt . is_decimal ( ) => Some ( Unknown ( UnknownKind :: Float ) ) ,
499+ UnknownKind :: Float if dt. is_integer ( ) => Some ( Unknown ( UnknownKind :: Float ) ) ,
457500 // Materialize str
458501 UnknownKind :: Str if dt. is_string ( ) | dt. is_enum ( ) => Some ( dt. clone ( ) ) ,
459502 // Materialize str
@@ -498,49 +541,6 @@ pub fn get_supertype_with_options(
498541 _ => Some ( Unknown ( UnknownKind :: Any ) )
499542 }
500543 } ,
501- #[ cfg( feature = "dtype-struct" ) ]
502- ( Struct ( fields_a) , Struct ( fields_b) ) => {
503- super_type_structs ( fields_a, fields_b)
504- }
505- #[ cfg( feature = "dtype-struct" ) ]
506- ( Struct ( fields_a) , rhs) if rhs. is_primitive_numeric ( ) => {
507- let mut new_fields = Vec :: with_capacity ( fields_a. len ( ) ) ;
508- for a in fields_a {
509- let st = get_supertype ( & a. dtype , rhs) ?;
510- new_fields. push ( Field :: new ( a. name . clone ( ) , st) )
511- }
512- Some ( Struct ( new_fields) )
513- }
514- #[ cfg( feature = "dtype-decimal" ) ]
515- ( Decimal ( p1, s1) , Decimal ( p2, s2) ) => {
516- Some ( Decimal ( ( * p1) . max ( * p2) , ( * s1) . max ( * s2) ) )
517- } ,
518- #[ cfg( all( feature = "dtype-decimal" , feature = "dtype-f16" ) ) ]
519- ( Decimal ( _, _) , Float16 ) => Some ( Float64 ) ,
520- #[ cfg( feature = "dtype-decimal" ) ]
521- ( Decimal ( _, _) , Float32 | Float64 ) => Some ( Float64 ) ,
522- #[ cfg( feature = "dtype-decimal" ) ]
523- ( Decimal ( prec, scale) , dt) if dt. is_signed_integer ( ) || dt. is_unsigned_integer ( ) => {
524- let fits = |v| { i128_to_dec128 ( v, * prec, * scale) . is_some ( ) } ;
525- let fits_orig_prec_scale = match dt {
526- UInt8 => fits ( u8:: MAX as i128 ) ,
527- UInt16 => fits ( u16:: MAX as i128 ) ,
528- UInt32 => fits ( u32:: MAX as i128 ) ,
529- UInt64 => fits ( u64:: MAX as i128 ) ,
530- UInt128 => false ,
531- Int8 => fits ( i8:: MAX as i128 ) ,
532- Int16 => fits ( i16:: MAX as i128 ) ,
533- Int32 => fits ( i32:: MAX as i128 ) ,
534- Int64 => fits ( i64:: MAX as i128 ) ,
535- Int128 => false ,
536- _ => unreachable ! ( ) ,
537- } ;
538- if fits_orig_prec_scale {
539- Some ( Decimal ( * prec, * scale) )
540- } else {
541- Some ( Decimal ( DEC128_MAX_PREC , * scale) )
542- }
543- }
544544 _ => None ,
545545 }
546546 }
0 commit comments