@@ -9,6 +9,7 @@ use arrow2_convert::{
99 ArrowDeserialize , ArrowField , ArrowSerialize ,
1010} ;
1111use std:: borrow:: Borrow ;
12+ use std:: f32:: INFINITY ;
1213use std:: sync:: Arc ;
1314
1415#[ test]
@@ -194,6 +195,34 @@ fn test_primitive_type_vec() {
194195 test_float_type ! ( f32 ) ;
195196 test_float_type ! ( f64 ) ;
196197
198+ // `arrow2::types::f16` isn't a native type so we can't just use `as`
199+ {
200+ let original_array: Vec < arrow2:: types:: f16 > =
201+ vec ! [ 1.0 , 2.5 , 47800.0 , 0.000012 , -0.0 , 0.0 , INFINITY ]
202+ . iter ( )
203+ . map ( |f| arrow2:: types:: f16:: from_f32 ( * f) )
204+ . collect ( ) ;
205+ let b: Box < dyn Array > = original_array. try_into_arrow ( ) . unwrap ( ) ;
206+ let round_trip: Vec < arrow2:: types:: f16 > = b. try_into_collection ( ) . unwrap ( ) ;
207+ assert_eq ! ( original_array, round_trip) ;
208+
209+ let original_array: Vec < Option < arrow2:: types:: f16 > > = vec ! [ Some ( 1. ) , None , Some ( 3. ) ]
210+ . iter ( )
211+ . map ( |f| f. map ( arrow2:: types:: f16:: from_f32) )
212+ . collect ( ) ;
213+ let b: Box < dyn Array > = original_array. try_into_arrow ( ) . unwrap ( ) ;
214+ let round_trip: Vec < Option < arrow2:: types:: f16 > > = b. try_into_collection ( ) . unwrap ( ) ;
215+ assert_eq ! ( original_array, round_trip) ;
216+
217+ let original_array: Vec < Option < arrow2:: types:: f16 > > = vec ! [ Some ( 1. ) , None , Some ( 3. ) ]
218+ . iter ( )
219+ . map ( |f| f. map ( arrow2:: types:: f16:: from_f32) )
220+ . collect ( ) ;
221+ let b: Arc < dyn Array > = original_array. try_into_arrow ( ) . unwrap ( ) ;
222+ let round_trip: Vec < Option < arrow2:: types:: f16 > > = b. try_into_collection ( ) . unwrap ( ) ;
223+ assert_eq ! ( original_array, round_trip) ;
224+ } ;
225+
197226 // i128
198227 // i128 is special since we need to require precision and scale so the TryIntoArrow trait
199228 // is not implemented for Vec<i128>.
0 commit comments