Skip to content

Commit 6b8125c

Browse files
committed
Avoid redundant check
1 parent 11d7c80 commit 6b8125c

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

arrow-array/src/builder/primitive_builder.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)