@@ -183,14 +183,10 @@ impl<T: ArrowPrimitiveType> PrimitiveBuilder<T> {
183183 ///
184184 /// # Panics
185185 ///
186- /// This method panics if `data_type` is not [PrimitiveArray::is_compatible]
186+ /// This method will not panic, but [`Self::build`], [`Self::finish`] will panics if `data_type` is
187+ /// not [PrimitiveArray::is_compatible] with the builder's primitive type
188+ /// `T`.
187189 pub fn with_data_type ( self , data_type : DataType ) -> Self {
188- assert ! (
189- PrimitiveArray :: <T >:: is_compatible( & data_type) ,
190- "incompatible data type for builder, expected {} got {}" ,
191- T :: DATA_TYPE ,
192- data_type
193- ) ;
194190 Self {
195191 data_type : Some ( data_type) ,
196192 ..self
@@ -662,9 +658,23 @@ mod tests {
662658 }
663659
664660 #[ test]
665- #[ should_panic( expected = "incompatible data type for builder, expected Int32 got Int64" ) ]
666- fn test_invalid_with_data_type ( ) {
667- Int32Builder :: new ( ) . with_data_type ( DataType :: Int64 ) ;
661+ #[ should_panic( expected = "PrimitiveArray expected data type Int32 got Int64" ) ]
662+ fn test_invalid_with_data_type_finish ( ) {
663+ Int32Builder :: new ( ) . with_data_type ( DataType :: Int64 ) . finish ( ) ;
664+ }
665+
666+ #[ test]
667+ #[ should_panic( expected = "PrimitiveArray expected data type Int32 got Int64" ) ]
668+ fn test_invalid_with_data_type_finish_cloned ( ) {
669+ Int32Builder :: new ( )
670+ . with_data_type ( DataType :: Int64 )
671+ . finish_cloned ( ) ;
672+ }
673+
674+ #[ test]
675+ #[ should_panic( expected = "PrimitiveArray expected data type Int32 got Int64" ) ]
676+ fn test_invalid_with_data_type_build ( ) {
677+ Int32Builder :: new ( ) . with_data_type ( DataType :: Int64 ) . build ( ) ;
668678 }
669679
670680 #[ test]
0 commit comments