diff --git a/benches/arithmetic_kernels.rs b/benches/arithmetic_kernels.rs index ce940c32e24..4d800bd7bec 100644 --- a/benches/arithmetic_kernels.rs +++ b/benches/arithmetic_kernels.rs @@ -22,7 +22,7 @@ fn bench_add(lhs: &PrimitiveArray, rhs: &PrimitiveArray) where T: NativeType + Add + NumCast, { - criterion::black_box(add(lhs, rhs)).unwrap(); + criterion::black_box(add(lhs, rhs)); } fn add_benchmark(c: &mut Criterion) { diff --git a/benches/comparison_kernels.rs b/benches/comparison_kernels.rs index 95a00326f44..5f288ee2819 100644 --- a/benches/comparison_kernels.rs +++ b/benches/comparison_kernels.rs @@ -3,14 +3,14 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; use arrow2::array::*; use arrow2::scalar::*; use arrow2::util::bench_util::*; -use arrow2::{compute::comparison::*, datatypes::DataType}; +use arrow2::{compute::comparison::eq, datatypes::DataType}; -fn bench_op(arr_a: &dyn Array, arr_b: &dyn Array, op: Operator) { - compare(black_box(arr_a), black_box(arr_b), op).unwrap(); +fn bench_op(arr_a: &dyn Array, arr_b: &dyn Array) { + eq(black_box(arr_a), black_box(arr_b)); } -fn bench_op_scalar(arr_a: &dyn Array, value_b: &dyn Scalar, op: Operator) { - compare_scalar(black_box(arr_a), black_box(value_b), op).unwrap(); +fn bench_op_scalar(arr_a: &dyn Array, value_b: &dyn Scalar) { + eq_scalar(black_box(arr_a), black_box(value_b)); } fn add_benchmark(c: &mut Criterion) { @@ -21,36 +21,30 @@ fn add_benchmark(c: &mut Criterion) { let arr_b = create_primitive_array_with_seed::(size, DataType::Float32, 0.0, 43); c.bench_function(&format!("f32 2^{}", log2_size), |b| { - b.iter(|| bench_op(&arr_a, &arr_b, Operator::Eq)) + b.iter(|| bench_op(&arr_a, &arr_b)) }); c.bench_function(&format!("f32 scalar 2^{}", log2_size), |b| { - b.iter(|| { - bench_op_scalar( - &arr_a, - &PrimitiveScalar::::from(Some(0.5)), - Operator::Eq, - ) - }) + b.iter(|| bench_op_scalar(&arr_a, &PrimitiveScalar::::from(Some(0.5)))) }); let arr_a = create_boolean_array(size, 0.0, 0.1); let arr_b = create_boolean_array(size, 0.0, 0.2); c.bench_function(&format!("bool 2^{}", log2_size), |b| { - b.iter(|| bench_op(&arr_a, &arr_b, Operator::Eq)) + b.iter(|| bench_op(&arr_a, &arr_b)) }); c.bench_function(&format!("bool scalar 2^{}", log2_size), |b| { - b.iter(|| bench_op_scalar(&arr_a, &BooleanScalar::from(Some(false)), Operator::Eq)) + b.iter(|| bench_op_scalar(&arr_a, &BooleanScalar::from(Some(false)))) }); let arr_a = create_string_array::(size, 4, 0.1, 42); let arr_b = create_string_array::(size, 4, 0.1, 43); c.bench_function(&format!("utf8 2^{}", log2_size), |b| { - b.iter(|| bench_op(&arr_a, &arr_b, Operator::Eq)) + b.iter(|| bench_op(&arr_a, &arr_b)) }); c.bench_function(&format!("utf8 2^{}", log2_size), |b| { - b.iter(|| bench_op_scalar(&arr_a, &Utf8Scalar::::from(Some("abc")), Operator::Eq)) + b.iter(|| bench_op_scalar(&arr_a, &Utf8Scalar::::from(Some("abc")))) }); }) } diff --git a/benches/write_ipc.rs b/benches/write_ipc.rs index ab60d3b856a..96b17299b75 100644 --- a/benches/write_ipc.rs +++ b/benches/write_ipc.rs @@ -16,7 +16,7 @@ fn write(array: &dyn Array) -> Result<()> { let batch = RecordBatch::try_new(Arc::new(schema.clone()), vec![clone(array).into()])?; let writer = Cursor::new(vec![]); - let mut writer = FileWriter::try_new(writer, &schema)?; + let mut writer = FileWriter::try_new(writer, &schema, Default::default())?; writer.write(&batch) } diff --git a/examples/arithmetics.rs b/examples/arithmetics.rs index 3123b951521..fe931b07e3e 100644 --- a/examples/arithmetics.rs +++ b/examples/arithmetics.rs @@ -1,48 +1,44 @@ use arrow2::array::{Array, PrimitiveArray}; -use arrow2::compute::arithmetics::*; +use arrow2::compute::arithmetics::basic::*; +use arrow2::compute::arithmetics::{add as dyn_add, can_add}; use arrow2::compute::arity::{binary, unary}; use arrow2::datatypes::DataType; -use arrow2::error::Result; -fn main() -> Result<()> { +fn main() { // say we have two arrays let array0 = PrimitiveArray::::from(&[Some(1), Some(2), Some(3)]); let array1 = PrimitiveArray::::from(&[Some(4), None, Some(6)]); // we can add them as follows: - let added = arithmetic_primitive(&array0, Operator::Add, &array1)?; + let added = add(&array0, &array1); assert_eq!( added, PrimitiveArray::::from(&[Some(5), None, Some(9)]) ); // subtract: - let subtracted = arithmetic_primitive(&array0, Operator::Subtract, &array1)?; + let subtracted = sub(&array0, &array1); assert_eq!( subtracted, PrimitiveArray::::from(&[Some(-3), None, Some(-3)]) ); // add a scalar: - let plus10 = arithmetic_primitive_scalar(&array0, Operator::Add, &10)?; + let plus10 = add_scalar(&array0, &10); assert_eq!( plus10, PrimitiveArray::::from(&[Some(11), Some(12), Some(13)]) ); - // when the array is a trait object, there is a similar API + // a similar API for trait objects: let array0 = &array0 as &dyn Array; let array1 = &array1 as &dyn Array; - // check whether the logical types support addition (they could be any `Array`). - assert!(can_arithmetic( - array0.data_type(), - Operator::Add, - array1.data_type() - )); + // check whether the logical types support addition. + assert!(can_add(array0.data_type(), array1.data_type())); // add them - let added = arithmetic(array0, Operator::Add, array1).unwrap(); + let added = dyn_add(array0, array1); assert_eq!( PrimitiveArray::::from(&[Some(5), None, Some(9)]), added.as_ref(), @@ -54,7 +50,7 @@ fn main() -> Result<()> { let array1 = PrimitiveArray::::from(&[Some(4), None, Some(6)]); let op = |x: i64, y: i64| x.pow(2) + y.pow(2); - let r = binary(&array0, &array1, DataType::Int64, op)?; + let r = binary(&array0, &array1, DataType::Int64, op); assert_eq!( r, PrimitiveArray::::from(&[Some(1 + 16), None, Some(9 + 36)]) @@ -79,6 +75,4 @@ fn main() -> Result<()> { rounded, PrimitiveArray::::from(&[Some(4), None, Some(5)]) ); - - Ok(()) } diff --git a/examples/csv_read_async.rs b/examples/csv_read_async.rs index fa0e9481fc5..c893f59d809 100644 --- a/examples/csv_read_async.rs +++ b/examples/csv_read_async.rs @@ -1,10 +1,8 @@ use std::sync::Arc; -use futures::io::Cursor; use tokio::fs::File; use tokio_util::compat::*; -use arrow2::array::*; use arrow2::error::Result; use arrow2::io::csv::read_async::*; diff --git a/examples/growable.rs b/examples/growable.rs index cc8b7573e49..c79d9cd0cbb 100644 --- a/examples/growable.rs +++ b/examples/growable.rs @@ -1,5 +1,5 @@ use arrow2::array::growable::{Growable, GrowablePrimitive}; -use arrow2::array::{Array, PrimitiveArray}; +use arrow2::array::PrimitiveArray; fn main() { // say we have two sorted arrays diff --git a/src/compute/arithmetics/basic/add.rs b/src/compute/arithmetics/basic/add.rs index 3edf52b7f06..5d4fd7215d5 100644 --- a/src/compute/arithmetics/basic/add.rs +++ b/src/compute/arithmetics/basic/add.rs @@ -8,8 +8,8 @@ use crate::{ bitmap::Bitmap, compute::{ arithmetics::{ - basic::check_same_type, ArrayAdd, ArrayCheckedAdd, ArrayOverflowingAdd, - ArraySaturatingAdd, ArrayWrappingAdd, NativeArithmetics, + ArrayAdd, ArrayCheckedAdd, ArrayOverflowingAdd, ArraySaturatingAdd, ArrayWrappingAdd, + NativeArithmetics, }, arity::{ binary, binary_checked, binary_with_bitmap, unary, unary_checked, unary_with_bitmap, @@ -28,7 +28,7 @@ use crate::{ /// /// let a = PrimitiveArray::from([None, Some(6), None, Some(6)]); /// let b = PrimitiveArray::from([Some(5), None, None, Some(6)]); -/// let result = add(&a, &b).unwrap(); +/// let result = add(&a, &b); /// let expected = PrimitiveArray::from([None, None, None, Some(12)]); /// assert_eq!(result, expected) /// ``` @@ -49,7 +49,7 @@ where /// /// let a = PrimitiveArray::from([Some(-100i8), Some(100i8), Some(100i8)]); /// let b = PrimitiveArray::from([Some(0i8), Some(100i8), Some(0i8)]); -/// let result = wrapping_add(&a, &b).unwrap(); +/// let result = wrapping_add(&a, &b); /// let expected = PrimitiveArray::from([Some(-100i8), Some(-56i8), Some(100i8)]); /// assert_eq!(result, expected); /// ``` @@ -72,7 +72,7 @@ where /// /// let a = PrimitiveArray::from([Some(100i8), Some(100i8), Some(100i8)]); /// let b = PrimitiveArray::from([Some(0i8), Some(100i8), Some(0i8)]); -/// let result = checked_add(&a, &b).unwrap(); +/// let result = checked_add(&a, &b); /// let expected = PrimitiveArray::from([Some(100i8), None, Some(100i8)]); /// assert_eq!(result, expected); /// ``` @@ -80,8 +80,6 @@ pub fn checked_add(lhs: &PrimitiveArray, rhs: &PrimitiveArray) -> Primi where T: NativeType + CheckedAdd, { - check_same_type(lhs, rhs).unwrap(); - let op = move |a: T, b: T| a.checked_add(&b); binary_checked(lhs, rhs, lhs.data_type().clone(), op) @@ -98,7 +96,7 @@ where /// /// let a = PrimitiveArray::from([Some(100i8)]); /// let b = PrimitiveArray::from([Some(100i8)]); -/// let result = saturating_add(&a, &b).unwrap(); +/// let result = saturating_add(&a, &b); /// let expected = PrimitiveArray::from([Some(127)]); /// assert_eq!(result, expected); /// ``` @@ -123,7 +121,7 @@ where /// /// let a = PrimitiveArray::from([Some(1i8), Some(100i8)]); /// let b = PrimitiveArray::from([Some(1i8), Some(100i8)]); -/// let (result, overflow) = overflowing_add(&a, &b).unwrap(); +/// let (result, overflow) = overflowing_add(&a, &b); /// let expected = PrimitiveArray::from([Some(2i8), Some(-56i8)]); /// assert_eq!(result, expected); /// ``` diff --git a/src/compute/arithmetics/basic/mod.rs b/src/compute/arithmetics/basic/mod.rs index 492a29b37a9..d9126e3a7f4 100644 --- a/src/compute/arithmetics/basic/mod.rs +++ b/src/compute/arithmetics/basic/mod.rs @@ -36,7 +36,7 @@ use super::super::arity::{unary, unary_checked}; /// /// # Examples /// ``` -/// use arrow2::compute::arithmetics::negate; +/// use arrow2::compute::arithmetics::basic::negate; /// use arrow2::array::PrimitiveArray; /// /// let a = PrimitiveArray::from([None, Some(6), None, Some(7)]); @@ -55,7 +55,7 @@ where /// /// # Examples /// ``` -/// use arrow2::compute::arithmetics::checked_negate; +/// use arrow2::compute::arithmetics::basic::checked_negate; /// use arrow2::array::{Array, PrimitiveArray}; /// /// let a = PrimitiveArray::from([None, Some(6), Some(i8::MIN), Some(7)]); @@ -75,7 +75,7 @@ where /// /// # Examples /// ``` -/// use arrow2::compute::arithmetics::wrapping_negate; +/// use arrow2::compute::arithmetics::basic::wrapping_negate; /// use arrow2::array::{Array, PrimitiveArray}; /// /// let a = PrimitiveArray::from([None, Some(6), Some(i8::MIN), Some(7)]); diff --git a/src/compute/arithmetics/basic/rem.rs b/src/compute/arithmetics/basic/rem.rs index 8210fe05ca2..30300385028 100644 --- a/src/compute/arithmetics/basic/rem.rs +++ b/src/compute/arithmetics/basic/rem.rs @@ -47,7 +47,7 @@ where /// /// let a = Int8Array::from(&[Some(-100i8), Some(10i8)]); /// let b = Int8Array::from(&[Some(100i8), Some(0i8)]); -/// let result = checked_rem(&a, &b).unwrap(); +/// let result = checked_rem(&a, &b); /// let expected = Int8Array::from(&[Some(-0i8), None]); /// assert_eq!(result, expected); /// ``` diff --git a/src/compute/arithmetics/basic/sub.rs b/src/compute/arithmetics/basic/sub.rs index b5e5ff843a0..d4067be3fc5 100644 --- a/src/compute/arithmetics/basic/sub.rs +++ b/src/compute/arithmetics/basic/sub.rs @@ -72,7 +72,7 @@ where /// /// let a = Int8Array::from(&[Some(100i8), Some(-100i8), Some(100i8)]); /// let b = Int8Array::from(&[Some(1i8), Some(100i8), Some(0i8)]); -/// let result = checked_sub(&a, &b).unwrap(); +/// let result = checked_sub(&a, &b); /// let expected = Int8Array::from(&[Some(99i8), None, Some(100i8)]); /// assert_eq!(result, expected); /// ``` diff --git a/src/compute/arithmetics/decimal/add.rs b/src/compute/arithmetics/decimal/add.rs index 98ccbd07dc6..e6a33ff4490 100644 --- a/src/compute/arithmetics/decimal/add.rs +++ b/src/compute/arithmetics/decimal/add.rs @@ -25,7 +25,7 @@ use super::{adjusted_precision_scale, get_parameters, max_value, number_digits}; /// /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::add::add; +/// use arrow2::compute::arithmetics::decimal::add; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// @@ -64,14 +64,14 @@ pub fn add(lhs: &PrimitiveArray, rhs: &PrimitiveArray) -> PrimitiveA /// /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::add::saturating_add; +/// use arrow2::compute::arithmetics::decimal::saturating_add; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// /// let a = PrimitiveArray::from([Some(99000i128), Some(11100i128), None, Some(22200i128)]).to(DataType::Decimal(5, 2)); /// let b = PrimitiveArray::from([Some(01000i128), Some(22200i128), None, Some(11100i128)]).to(DataType::Decimal(5, 2)); /// -/// let result = saturating_add(&a, &b).unwrap(); +/// let result = saturating_add(&a, &b); /// let expected = PrimitiveArray::from([Some(99999i128), Some(33300i128), None, Some(33300i128)]).to(DataType::Decimal(5, 2)); /// /// assert_eq!(result, expected); @@ -108,7 +108,7 @@ pub fn saturating_add( /// /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::add::checked_add; +/// use arrow2::compute::arithmetics::decimal::checked_add; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// @@ -172,13 +172,13 @@ impl ArraySaturatingAdd> for PrimitiveArray { /// ``` /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::add::adaptive_add; +/// use arrow2::compute::arithmetics::decimal::adaptive_add; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// /// let a = PrimitiveArray::from([Some(11111_11i128)]).to(DataType::Decimal(7, 2)); /// let b = PrimitiveArray::from([Some(11111_111i128)]).to(DataType::Decimal(8, 3)); -/// let result = adaptive_add(&a, &b); +/// let result = adaptive_add(&a, &b).unwrap(); /// let expected = PrimitiveArray::from([Some(22222_221i128)]).to(DataType::Decimal(8, 3)); /// /// assert_eq!(result, expected); diff --git a/src/compute/arithmetics/decimal/div.rs b/src/compute/arithmetics/decimal/div.rs index 92c02602040..b83e057f632 100644 --- a/src/compute/arithmetics/decimal/div.rs +++ b/src/compute/arithmetics/decimal/div.rs @@ -24,7 +24,7 @@ use super::{adjusted_precision_scale, get_parameters, max_value, number_digits}; /// /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::div::div; +/// use arrow2::compute::arithmetics::decimal::div; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// @@ -77,7 +77,7 @@ pub fn div(lhs: &PrimitiveArray, rhs: &PrimitiveArray) -> PrimitiveA /// /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::div::saturating_div; +/// use arrow2::compute::arithmetics::decimal::saturating_div; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// @@ -126,7 +126,7 @@ pub fn saturating_div( /// /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::div::checked_div; +/// use arrow2::compute::arithmetics::decimal::checked_div; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// @@ -188,13 +188,13 @@ impl ArrayCheckedDiv> for PrimitiveArray { /// ``` /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::div::adaptive_div; +/// use arrow2::compute::arithmetics::decimal::adaptive_div; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// /// let a = PrimitiveArray::from([Some(1000_00i128)]).to(DataType::Decimal(7, 2)); /// let b = PrimitiveArray::from([Some(10_0000i128)]).to(DataType::Decimal(6, 4)); -/// let result = adaptive_div(&a, &b); +/// let result = adaptive_div(&a, &b).unwrap(); /// let expected = PrimitiveArray::from([Some(100_0000i128)]).to(DataType::Decimal(9, 4)); /// /// assert_eq!(result, expected); diff --git a/src/compute/arithmetics/decimal/mul.rs b/src/compute/arithmetics/decimal/mul.rs index 8ccf5c7d9dd..b3858aa8e13 100644 --- a/src/compute/arithmetics/decimal/mul.rs +++ b/src/compute/arithmetics/decimal/mul.rs @@ -23,7 +23,7 @@ use super::{adjusted_precision_scale, get_parameters, max_value, number_digits}; /// /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::mul::mul; +/// use arrow2::compute::arithmetics::decimal::mul; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// @@ -78,7 +78,7 @@ pub fn mul(lhs: &PrimitiveArray, rhs: &PrimitiveArray) -> PrimitiveA /// /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::mul::saturating_mul; +/// use arrow2::compute::arithmetics::decimal::saturating_mul; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// @@ -128,7 +128,7 @@ pub fn saturating_mul( /// /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::mul::checked_mul; +/// use arrow2::compute::arithmetics::decimal::checked_mul; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// @@ -197,7 +197,7 @@ impl ArraySaturatingMul> for PrimitiveArray { /// ``` /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::mul::adaptive_mul; +/// use arrow2::compute::arithmetics::decimal::adaptive_mul; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// diff --git a/src/compute/arithmetics/decimal/sub.rs b/src/compute/arithmetics/decimal/sub.rs index 973bc11e4c0..d7870401a3f 100644 --- a/src/compute/arithmetics/decimal/sub.rs +++ b/src/compute/arithmetics/decimal/sub.rs @@ -22,14 +22,14 @@ use super::{adjusted_precision_scale, get_parameters, max_value, number_digits}; /// /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::sub::sub; +/// use arrow2::compute::arithmetics::decimal::sub; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// /// let a = PrimitiveArray::from([Some(1i128), Some(1i128), None, Some(2i128)]).to(DataType::Decimal(5, 2)); /// let b = PrimitiveArray::from([Some(1i128), Some(2i128), None, Some(2i128)]).to(DataType::Decimal(5, 2)); /// -/// let result = sub(&a, &b).unwrap(); +/// let result = sub(&a, &b); /// let expected = PrimitiveArray::from([Some(0i128), Some(-1i128), None, Some(0i128)]).to(DataType::Decimal(5, 2)); /// /// assert_eq!(result, expected); @@ -62,14 +62,14 @@ pub fn sub(lhs: &PrimitiveArray, rhs: &PrimitiveArray) -> PrimitiveA /// /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::sub::saturating_sub; +/// use arrow2::compute::arithmetics::decimal::saturating_sub; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// /// let a = PrimitiveArray::from([Some(-99000i128), Some(11100i128), None, Some(22200i128)]).to(DataType::Decimal(5, 2)); /// let b = PrimitiveArray::from([Some(01000i128), Some(22200i128), None, Some(11100i128)]).to(DataType::Decimal(5, 2)); /// -/// let result = saturating_sub(&a, &b).unwrap(); +/// let result = saturating_sub(&a, &b); /// let expected = PrimitiveArray::from([Some(-99999i128), Some(-11100i128), None, Some(11100i128)]).to(DataType::Decimal(5, 2)); /// /// assert_eq!(result, expected); @@ -128,14 +128,14 @@ impl ArraySaturatingSub> for PrimitiveArray { /// /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::sub::checked_sub; +/// use arrow2::compute::arithmetics::decimal::checked_sub; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// /// let a = PrimitiveArray::from([Some(-99000i128), Some(11100i128), None, Some(22200i128)]).to(DataType::Decimal(5, 2)); /// let b = PrimitiveArray::from([Some(01000i128), Some(22200i128), None, Some(11100i128)]).to(DataType::Decimal(5, 2)); /// -/// let result = checked_sub(&a, &b).unwrap(); +/// let result = checked_sub(&a, &b); /// let expected = PrimitiveArray::from([None, Some(-11100i128), None, Some(11100i128)]).to(DataType::Decimal(5, 2)); /// /// assert_eq!(result, expected); @@ -171,7 +171,7 @@ pub fn checked_sub(lhs: &PrimitiveArray, rhs: &PrimitiveArray) -> Pr /// ``` /// # Examples /// ``` -/// use arrow2::compute::arithmetics::decimal::sub::adaptive_sub; +/// use arrow2::compute::arithmetics::decimal::adaptive_sub; /// use arrow2::array::PrimitiveArray; /// use arrow2::datatypes::DataType; /// diff --git a/src/compute/arithmetics/time.rs b/src/compute/arithmetics/time.rs index d622652823e..9ef1930e95e 100644 --- a/src/compute/arithmetics/time.rs +++ b/src/compute/arithmetics/time.rs @@ -86,7 +86,7 @@ fn create_scale(lhs: &DataType, rhs: &DataType) -> Result { /// let duration = PrimitiveArray::from([Some(10i64), Some(20i64), None, Some(30i64)]) /// .to(DataType::Duration(TimeUnit::Second)); /// -/// let result = add_duration(×tamp, &duration).unwrap(); +/// let result = add_duration(×tamp, &duration); /// let expected = PrimitiveArray::from([ /// Some(100010i64), /// Some(200020i64), @@ -141,7 +141,7 @@ where /// let duration = PrimitiveArray::from([Some(10i64), Some(20i64), None, Some(30i64)]) /// .to(DataType::Duration(TimeUnit::Second)); /// -/// let result = subtract_duration(×tamp, &duration).unwrap(); +/// let result = subtract_duration(×tamp, &duration); /// let expected = PrimitiveArray::from([ /// Some(99990i64), /// Some(199980i64), diff --git a/tests/it/compute/aggregate/sum.rs b/tests/it/compute/aggregate/sum.rs index 56c93624a0e..c1d8190359b 100644 --- a/tests/it/compute/aggregate/sum.rs +++ b/tests/it/compute/aggregate/sum.rs @@ -46,7 +46,7 @@ fn test_primitive_array_sum_large_64() { .map(|i| if i % 3 == 0 { Some(0) } else { Some(i) }) .collect(); // create an array that actually has non-zero values at the invalid indices - let c = arithmetics::basic::add(&a, &b).unwrap(); + let c = arithmetics::basic::add(&a, &b); assert_eq!( Some((1..=100).filter(|i| i % 3 == 0).sum()), sum_primitive(&c) diff --git a/tests/it/compute/arithmetics/basic/add.rs b/tests/it/compute/arithmetics/basic/add.rs index 32ccb5a0230..c02f4c7d71c 100644 --- a/tests/it/compute/arithmetics/basic/add.rs +++ b/tests/it/compute/arithmetics/basic/add.rs @@ -6,24 +6,23 @@ use arrow2::compute::arithmetics::{ }; #[test] +#[should_panic] fn test_add_mismatched_length() { let a = Int32Array::from_slice(&[5, 6]); let b = Int32Array::from_slice(&[5]); - add(&a, &b) - .err() - .expect("should have failed due to different lengths"); + add(&a, &b); } #[test] fn test_add() { let a = Int32Array::from(&[None, Some(6), None, Some(6)]); let b = Int32Array::from(&[Some(5), None, None, Some(6)]); - let result = add(&a, &b).unwrap(); + let result = add(&a, &b); let expected = Int32Array::from(&[None, None, None, Some(12)]); assert_eq!(result, expected); // Trait testing - let result = a.add(&b).unwrap(); + let result = a.add(&b); assert_eq!(result, expected); } @@ -32,25 +31,25 @@ fn test_add() { fn test_add_panic() { let a = Int8Array::from(&[Some(100i8)]); let b = Int8Array::from(&[Some(100i8)]); - let _ = add(&a, &b); + add(&a, &b); } #[test] fn test_add_checked() { let a = Int32Array::from(&[None, Some(6), None, Some(6)]); let b = Int32Array::from(&[Some(5), None, None, Some(6)]); - let result = checked_add(&a, &b).unwrap(); + let result = checked_add(&a, &b); let expected = Int32Array::from(&[None, None, None, Some(12)]); assert_eq!(result, expected); let a = Int8Array::from(&[Some(100i8), Some(100i8), Some(100i8)]); let b = Int8Array::from(&[Some(0i8), Some(100i8), Some(0i8)]); - let result = checked_add(&a, &b).unwrap(); + let result = checked_add(&a, &b); let expected = Int8Array::from(&[Some(100i8), None, Some(100i8)]); assert_eq!(result, expected); // Trait testing - let result = a.checked_add(&b).unwrap(); + let result = a.checked_add(&b); assert_eq!(result, expected); } @@ -58,18 +57,18 @@ fn test_add_checked() { fn test_add_saturating() { let a = Int32Array::from(&[None, Some(6), None, Some(6)]); let b = Int32Array::from(&[Some(5), None, None, Some(6)]); - let result = saturating_add(&a, &b).unwrap(); + let result = saturating_add(&a, &b); let expected = Int32Array::from(&[None, None, None, Some(12)]); assert_eq!(result, expected); let a = Int8Array::from(&[Some(100i8)]); let b = Int8Array::from(&[Some(100i8)]); - let result = saturating_add(&a, &b).unwrap(); + let result = saturating_add(&a, &b); let expected = Int8Array::from(&[Some(127)]); assert_eq!(result, expected); // Trait testing - let result = a.saturating_add(&b).unwrap(); + let result = a.saturating_add(&b); assert_eq!(result, expected); } @@ -77,20 +76,20 @@ fn test_add_saturating() { fn test_add_overflowing() { let a = Int32Array::from(&[None, Some(6), None, Some(6)]); let b = Int32Array::from(&[Some(5), None, None, Some(6)]); - let (result, overflow) = overflowing_add(&a, &b).unwrap(); + let (result, overflow) = overflowing_add(&a, &b); let expected = Int32Array::from(&[None, None, None, Some(12)]); assert_eq!(result, expected); assert_eq!(overflow, Bitmap::from([false, false, false, false])); let a = Int8Array::from(&[Some(1i8), Some(100i8)]); let b = Int8Array::from(&[Some(1i8), Some(100i8)]); - let (result, overflow) = overflowing_add(&a, &b).unwrap(); + let (result, overflow) = overflowing_add(&a, &b); let expected = Int8Array::from(&[Some(2i8), Some(-56i8)]); assert_eq!(result, expected); assert_eq!(overflow, Bitmap::from([false, true])); // Trait testing - let (result, overflow) = a.overflowing_add(&b).unwrap(); + let (result, overflow) = a.overflowing_add(&b); assert_eq!(result, expected); assert_eq!(overflow, Bitmap::from([false, true])); } @@ -103,7 +102,7 @@ fn test_add_scalar() { assert_eq!(result, expected); // Trait testing - let result = a.add(&1i32).unwrap(); + let result = a.add(&1i32); assert_eq!(result, expected); } @@ -120,7 +119,7 @@ fn test_add_scalar_checked() { assert_eq!(result, expected); // Trait testing - let result = a.checked_add(&100i8).unwrap(); + let result = a.checked_add(&100i8); assert_eq!(result, expected); } @@ -137,7 +136,7 @@ fn test_add_scalar_saturating() { assert_eq!(result, expected); // Trait testing - let result = a.saturating_add(&100i8).unwrap(); + let result = a.saturating_add(&100i8); assert_eq!(result, expected); } @@ -156,7 +155,7 @@ fn test_add_scalar_overflowing() { assert_eq!(overflow, Bitmap::from([false, true])); // Trait testing - let (result, overflow) = a.overflowing_add(&100i8).unwrap(); + let (result, overflow) = a.overflowing_add(&100i8); assert_eq!(result, expected); assert_eq!(overflow, Bitmap::from([false, true])); } diff --git a/tests/it/compute/arithmetics/basic/div.rs b/tests/it/compute/arithmetics/basic/div.rs index 6fd00c7bf4f..8547795842d 100644 --- a/tests/it/compute/arithmetics/basic/div.rs +++ b/tests/it/compute/arithmetics/basic/div.rs @@ -3,24 +3,23 @@ use arrow2::compute::arithmetics::basic::*; use arrow2::compute::arithmetics::{ArrayCheckedDiv, ArrayDiv}; #[test] +#[should_panic] fn test_div_mismatched_length() { let a = Int32Array::from_slice(&[5, 6]); let b = Int32Array::from_slice(&[5]); - div(&a, &b) - .err() - .expect("should have failed due to different lengths"); + div(&a, &b); } #[test] fn test_div() { let a = Int32Array::from(&[Some(5), Some(6)]); let b = Int32Array::from(&[Some(5), Some(6)]); - let result = div(&a, &b).unwrap(); + let result = div(&a, &b); let expected = Int32Array::from(&[Some(1), Some(1)]); assert_eq!(result, expected); // Trait testing - let result = a.div(&b).unwrap(); + let result = a.div(&b); assert_eq!(result, expected); } @@ -36,18 +35,18 @@ fn test_div_panic() { fn test_div_checked() { let a = Int32Array::from(&[Some(5), None, Some(3), Some(6)]); let b = Int32Array::from(&[Some(5), Some(3), None, Some(6)]); - let result = checked_div(&a, &b).unwrap(); + let result = checked_div(&a, &b); let expected = Int32Array::from(&[Some(1), None, None, Some(1)]); assert_eq!(result, expected); let a = Int32Array::from(&[Some(5), None, Some(3), Some(6)]); let b = Int32Array::from(&[Some(5), Some(0), Some(0), Some(6)]); - let result = checked_div(&a, &b).unwrap(); + let result = checked_div(&a, &b); let expected = Int32Array::from(&[Some(1), None, None, Some(1)]); assert_eq!(result, expected); // Trait testing - let result = a.checked_div(&b).unwrap(); + let result = a.checked_div(&b); assert_eq!(result, expected); } @@ -59,7 +58,7 @@ fn test_div_scalar() { assert_eq!(result, expected); // Trait testing - let result = a.div(&1i32).unwrap(); + let result = a.div(&1i32); assert_eq!(result, expected); // check the strength reduced branches @@ -97,6 +96,6 @@ fn test_div_scalar_checked() { assert_eq!(result, expected); // Trait testing - let result = a.checked_div(&0).unwrap(); + let result = a.checked_div(&0); assert_eq!(result, expected); } diff --git a/tests/it/compute/arithmetics/basic/mul.rs b/tests/it/compute/arithmetics/basic/mul.rs index 5c2b8e57a58..d202edecb15 100644 --- a/tests/it/compute/arithmetics/basic/mul.rs +++ b/tests/it/compute/arithmetics/basic/mul.rs @@ -6,24 +6,23 @@ use arrow2::compute::arithmetics::{ }; #[test] +#[should_panic] fn test_mul_mismatched_length() { let a = Int32Array::from_slice(&[5, 6]); let b = Int32Array::from_slice(&[5]); - mul(&a, &b) - .err() - .expect("should have failed due to different lengths"); + mul(&a, &b); } #[test] fn test_mul() { let a = Int32Array::from(&[None, Some(6), None, Some(6)]); let b = Int32Array::from(&[Some(5), None, None, Some(6)]); - let result = mul(&a, &b).unwrap(); + let result = mul(&a, &b); let expected = Int32Array::from(&[None, None, None, Some(36)]); assert_eq!(result, expected); // Trait testing - let result = a.mul(&b).unwrap(); + let result = a.mul(&b); assert_eq!(result, expected); } @@ -39,18 +38,18 @@ fn test_mul_panic() { fn test_mul_checked() { let a = Int32Array::from(&[None, Some(6), None, Some(6)]); let b = Int32Array::from(&[Some(5), None, None, Some(6)]); - let result = checked_mul(&a, &b).unwrap(); + let result = checked_mul(&a, &b); let expected = Int32Array::from(&[None, None, None, Some(36)]); assert_eq!(result, expected); let a = Int8Array::from(&[Some(100i8), Some(100i8), Some(100i8)]); let b = Int8Array::from(&[Some(1i8), Some(100i8), Some(1i8)]); - let result = checked_mul(&a, &b).unwrap(); + let result = checked_mul(&a, &b); let expected = Int8Array::from(&[Some(100i8), None, Some(100i8)]); assert_eq!(result, expected); // Trait testing - let result = a.checked_mul(&b).unwrap(); + let result = a.checked_mul(&b); assert_eq!(result, expected); } @@ -58,18 +57,18 @@ fn test_mul_checked() { fn test_mul_saturating() { let a = Int32Array::from(&[None, Some(6), None, Some(6)]); let b = Int32Array::from(&[Some(5), None, None, Some(6)]); - let result = saturating_mul(&a, &b).unwrap(); + let result = saturating_mul(&a, &b); let expected = Int32Array::from(&[None, None, None, Some(36)]); assert_eq!(result, expected); let a = Int8Array::from(&[Some(-100i8)]); let b = Int8Array::from(&[Some(100i8)]); - let result = saturating_mul(&a, &b).unwrap(); + let result = saturating_mul(&a, &b); let expected = Int8Array::from(&[Some(-128)]); assert_eq!(result, expected); // Trait testing - let result = a.saturating_mul(&b).unwrap(); + let result = a.saturating_mul(&b); assert_eq!(result, expected); } @@ -77,20 +76,20 @@ fn test_mul_saturating() { fn test_mul_overflowing() { let a = Int32Array::from(&[None, Some(6), None, Some(6)]); let b = Int32Array::from(&[Some(5), None, None, Some(6)]); - let (result, overflow) = overflowing_mul(&a, &b).unwrap(); + let (result, overflow) = overflowing_mul(&a, &b); let expected = Int32Array::from(&[None, None, None, Some(36)]); assert_eq!(result, expected); assert_eq!(overflow, Bitmap::from([false, false, false, false])); let a = Int8Array::from(&[Some(1i8), Some(-100i8)]); let b = Int8Array::from(&[Some(1i8), Some(100i8)]); - let (result, overflow) = overflowing_mul(&a, &b).unwrap(); + let (result, overflow) = overflowing_mul(&a, &b); let expected = Int8Array::from(&[Some(1i8), Some(-16i8)]); assert_eq!(result, expected); assert_eq!(overflow, Bitmap::from([false, true])); // Trait testing - let (result, overflow) = a.overflowing_mul(&b).unwrap(); + let (result, overflow) = a.overflowing_mul(&b); assert_eq!(result, expected); assert_eq!(overflow, Bitmap::from([false, true])); } @@ -103,7 +102,7 @@ fn test_mul_scalar() { assert_eq!(result, expected); // Trait testing - let result = a.mul(&1i32).unwrap(); + let result = a.mul(&1i32); assert_eq!(result, expected); } @@ -120,7 +119,7 @@ fn test_mul_scalar_checked() { assert_eq!(result, expected); // Trait testing - let result = a.checked_mul(&100i8).unwrap(); + let result = a.checked_mul(&100i8); assert_eq!(result, expected); } @@ -137,7 +136,7 @@ fn test_mul_scalar_saturating() { assert_eq!(result, expected); // Trait testing - let result = a.saturating_mul(&100i8).unwrap(); + let result = a.saturating_mul(&100i8); assert_eq!(result, expected); } @@ -156,7 +155,7 @@ fn test_mul_scalar_overflowing() { assert_eq!(overflow, Bitmap::from([false, true])); // Trait testing - let (result, overflow) = a.overflowing_mul(&100i8).unwrap(); + let (result, overflow) = a.overflowing_mul(&100i8); assert_eq!(result, expected); assert_eq!(overflow, Bitmap::from([false, true])); } diff --git a/tests/it/compute/arithmetics/basic/rem.rs b/tests/it/compute/arithmetics/basic/rem.rs index e5a487b4f16..52f6db82702 100644 --- a/tests/it/compute/arithmetics/basic/rem.rs +++ b/tests/it/compute/arithmetics/basic/rem.rs @@ -3,24 +3,23 @@ use arrow2::compute::arithmetics::basic::*; use arrow2::compute::arithmetics::{ArrayCheckedRem, ArrayRem}; #[test] +#[should_panic] fn test_rem_mismatched_length() { let a = Int32Array::from_slice(&[5, 6]); let b = Int32Array::from_slice(&[5]); - rem(&a, &b) - .err() - .expect("should have failed due to different lengths"); + rem(&a, &b); } #[test] fn test_rem() { let a = Int32Array::from(&[Some(5), Some(6)]); let b = Int32Array::from(&[Some(4), Some(4)]); - let result = rem(&a, &b).unwrap(); + let result = rem(&a, &b); let expected = Int32Array::from(&[Some(1), Some(2)]); assert_eq!(result, expected); // Trait testing - let result = a.rem(&b).unwrap(); + let result = a.rem(&b); assert_eq!(result, expected); } @@ -36,18 +35,18 @@ fn test_rem_panic() { fn test_rem_checked() { let a = Int32Array::from(&[Some(5), None, Some(3), Some(6)]); let b = Int32Array::from(&[Some(5), Some(3), None, Some(5)]); - let result = checked_rem(&a, &b).unwrap(); + let result = checked_rem(&a, &b); let expected = Int32Array::from(&[Some(0), None, None, Some(1)]); assert_eq!(result, expected); let a = Int32Array::from(&[Some(5), None, Some(3), Some(6)]); let b = Int32Array::from(&[Some(5), Some(0), Some(0), Some(5)]); - let result = checked_rem(&a, &b).unwrap(); + let result = checked_rem(&a, &b); let expected = Int32Array::from(&[Some(0), None, None, Some(1)]); assert_eq!(result, expected); // Trait testing - let result = a.checked_rem(&b).unwrap(); + let result = a.checked_rem(&b); assert_eq!(result, expected); } @@ -59,7 +58,7 @@ fn test_rem_scalar() { assert_eq!(result, expected); // Trait testing - let result = a.rem(&2i32).unwrap(); + let result = a.rem(&2i32); assert_eq!(result, expected); // check the strength reduced branches @@ -97,6 +96,6 @@ fn test_rem_scalar_checked() { assert_eq!(result, expected); // Trait testing - let result = a.checked_rem(&0).unwrap(); + let result = a.checked_rem(&0); assert_eq!(result, expected); } diff --git a/tests/it/compute/arithmetics/basic/sub.rs b/tests/it/compute/arithmetics/basic/sub.rs index 5c638c6e596..c56719f64b4 100644 --- a/tests/it/compute/arithmetics/basic/sub.rs +++ b/tests/it/compute/arithmetics/basic/sub.rs @@ -6,24 +6,23 @@ use arrow2::compute::arithmetics::{ }; #[test] +#[should_panic] fn test_sub_mismatched_length() { let a = Int32Array::from_slice(&[5, 6]); let b = Int32Array::from_slice(&[5]); - sub(&a, &b) - .err() - .expect("should have failed due to different lengths"); + sub(&a, &b); } #[test] fn test_sub() { let a = Int32Array::from(&[None, Some(6), None, Some(6)]); let b = Int32Array::from(&[Some(5), None, None, Some(6)]); - let result = sub(&a, &b).unwrap(); + let result = sub(&a, &b); let expected = Int32Array::from(&[None, None, None, Some(0)]); assert_eq!(result, expected); // Trait testing - let result = a.sub(&b).unwrap(); + let result = a.sub(&b); assert_eq!(result, expected); } @@ -39,18 +38,18 @@ fn test_sub_panic() { fn test_sub_checked() { let a = Int32Array::from(&[None, Some(6), None, Some(6)]); let b = Int32Array::from(&[Some(5), None, None, Some(6)]); - let result = checked_sub(&a, &b).unwrap(); + let result = checked_sub(&a, &b); let expected = Int32Array::from(&[None, None, None, Some(0)]); assert_eq!(result, expected); let a = Int8Array::from(&[Some(100i8), Some(-100i8), Some(100i8)]); let b = Int8Array::from(&[Some(1i8), Some(100i8), Some(0i8)]); - let result = checked_sub(&a, &b).unwrap(); + let result = checked_sub(&a, &b); let expected = Int8Array::from(&[Some(99i8), None, Some(100i8)]); assert_eq!(result, expected); // Trait testing - let result = a.checked_sub(&b).unwrap(); + let result = a.checked_sub(&b); assert_eq!(result, expected); } @@ -58,18 +57,18 @@ fn test_sub_checked() { fn test_sub_saturating() { let a = Int32Array::from(&[None, Some(6), None, Some(6)]); let b = Int32Array::from(&[Some(5), None, None, Some(6)]); - let result = saturating_sub(&a, &b).unwrap(); + let result = saturating_sub(&a, &b); let expected = Int32Array::from(&[None, None, None, Some(0)]); assert_eq!(result, expected); let a = Int8Array::from(&[Some(-100i8)]); let b = Int8Array::from(&[Some(100i8)]); - let result = saturating_sub(&a, &b).unwrap(); + let result = saturating_sub(&a, &b); let expected = Int8Array::from(&[Some(-128)]); assert_eq!(result, expected); // Trait testing - let result = a.saturating_sub(&b).unwrap(); + let result = a.saturating_sub(&b); assert_eq!(result, expected); } @@ -77,20 +76,20 @@ fn test_sub_saturating() { fn test_sub_overflowing() { let a = Int32Array::from(&[None, Some(6), None, Some(6)]); let b = Int32Array::from(&[Some(5), None, None, Some(6)]); - let (result, overflow) = overflowing_sub(&a, &b).unwrap(); + let (result, overflow) = overflowing_sub(&a, &b); let expected = Int32Array::from(&[None, None, None, Some(0)]); assert_eq!(result, expected); assert_eq!(overflow, Bitmap::from([false, false, false, false])); let a = Int8Array::from(&[Some(1i8), Some(-100i8)]); let b = Int8Array::from(&[Some(1i8), Some(100i8)]); - let (result, overflow) = overflowing_sub(&a, &b).unwrap(); + let (result, overflow) = overflowing_sub(&a, &b); let expected = Int8Array::from(&[Some(0i8), Some(56i8)]); assert_eq!(result, expected); assert_eq!(overflow, Bitmap::from([false, true])); // Trait testing - let (result, overflow) = a.overflowing_sub(&b).unwrap(); + let (result, overflow) = a.overflowing_sub(&b); assert_eq!(result, expected); assert_eq!(overflow, Bitmap::from([false, true])); } @@ -103,7 +102,7 @@ fn test_sub_scalar() { assert_eq!(result, expected); // Trait testing - let result = a.sub(&1i32).unwrap(); + let result = a.sub(&1i32); assert_eq!(result, expected); } @@ -120,7 +119,7 @@ fn test_sub_scalar_checked() { assert_eq!(result, expected); // Trait testing - let result = a.checked_sub(&100i8).unwrap(); + let result = a.checked_sub(&100i8); assert_eq!(result, expected); } @@ -137,7 +136,7 @@ fn test_sub_scalar_saturating() { assert_eq!(result, expected); // Trait testing - let result = a.saturating_sub(&100i8).unwrap(); + let result = a.saturating_sub(&100i8); assert_eq!(result, expected); } @@ -156,7 +155,7 @@ fn test_sub_scalar_overflowing() { assert_eq!(overflow, Bitmap::from([false, true])); // Trait testing - let (result, overflow) = a.overflowing_sub(&100i8).unwrap(); + let (result, overflow) = a.overflowing_sub(&100i8); assert_eq!(result, expected); assert_eq!(overflow, Bitmap::from([false, true])); } diff --git a/tests/it/compute/arithmetics/decimal/add.rs b/tests/it/compute/arithmetics/decimal/add.rs index 7f772a5b933..45af77b1519 100644 --- a/tests/it/compute/arithmetics/decimal/add.rs +++ b/tests/it/compute/arithmetics/decimal/add.rs @@ -1,7 +1,7 @@ #![allow(clippy::zero_prefixed_literal, clippy::inconsistent_digit_grouping)] use arrow2::array::*; -use arrow2::compute::arithmetics::decimal::add::*; +use arrow2::compute::arithmetics::decimal::{adaptive_add, add, checked_add, saturating_add}; use arrow2::compute::arithmetics::{ArrayAdd, ArrayCheckedAdd, ArraySaturatingAdd}; use arrow2::datatypes::DataType; @@ -13,26 +13,23 @@ fn test_add_normal() { let b = PrimitiveArray::from([Some(22222i128), Some(22200i128), None, Some(11100i128)]) .to(DataType::Decimal(5, 2)); - let result = add(&a, &b).unwrap(); + let result = add(&a, &b); let expected = PrimitiveArray::from([Some(33333i128), Some(33300i128), None, Some(33300i128)]) .to(DataType::Decimal(5, 2)); assert_eq!(result, expected); // Testing trait - let result = a.add(&b).unwrap(); + let result = a.add(&b); assert_eq!(result, expected); } #[test] +#[should_panic] fn test_add_decimal_wrong_precision() { let a = PrimitiveArray::from([None]).to(DataType::Decimal(5, 2)); let b = PrimitiveArray::from([None]).to(DataType::Decimal(6, 2)); - let result = add(&a, &b); - - if result.is_ok() { - panic!("Should panic for different precision"); - } + add(&a, &b); } #[test] @@ -51,14 +48,14 @@ fn test_add_saturating() { let b = PrimitiveArray::from([Some(22222i128), Some(22200i128), None, Some(11100i128)]) .to(DataType::Decimal(5, 2)); - let result = saturating_add(&a, &b).unwrap(); + let result = saturating_add(&a, &b); let expected = PrimitiveArray::from([Some(33333i128), Some(33300i128), None, Some(33300i128)]) .to(DataType::Decimal(5, 2)); assert_eq!(result, expected); // Testing trait - let result = a.saturating_add(&b).unwrap(); + let result = a.saturating_add(&b); assert_eq!(result, expected); } @@ -79,7 +76,7 @@ fn test_add_saturating_overflow() { ]) .to(DataType::Decimal(5, 2)); - let result = saturating_add(&a, &b).unwrap(); + let result = saturating_add(&a, &b); let expected = PrimitiveArray::from([ Some(99999i128), @@ -92,7 +89,7 @@ fn test_add_saturating_overflow() { assert_eq!(result, expected); // Testing trait - let result = a.saturating_add(&b).unwrap(); + let result = a.saturating_add(&b); assert_eq!(result, expected); } @@ -104,14 +101,14 @@ fn test_add_checked() { let b = PrimitiveArray::from([Some(22222i128), Some(22200i128), None, Some(11100i128)]) .to(DataType::Decimal(5, 2)); - let result = checked_add(&a, &b).unwrap(); + let result = checked_add(&a, &b); let expected = PrimitiveArray::from([Some(33333i128), Some(33300i128), None, Some(33300i128)]) .to(DataType::Decimal(5, 2)); assert_eq!(result, expected); // Testing trait - let result = a.checked_add(&b).unwrap(); + let result = a.checked_add(&b); assert_eq!(result, expected); } @@ -119,12 +116,12 @@ fn test_add_checked() { fn test_add_checked_overflow() { let a = PrimitiveArray::from([Some(1i128), Some(99999i128)]).to(DataType::Decimal(5, 2)); let b = PrimitiveArray::from([Some(1i128), Some(1i128)]).to(DataType::Decimal(5, 2)); - let result = checked_add(&a, &b).unwrap(); + let result = checked_add(&a, &b); let expected = PrimitiveArray::from([Some(2i128), None]).to(DataType::Decimal(5, 2)); assert_eq!(result, expected); // Testing trait - let result = a.checked_add(&b).unwrap(); + let result = a.checked_add(&b); assert_eq!(result, expected); } diff --git a/tests/it/compute/arithmetics/decimal/div.rs b/tests/it/compute/arithmetics/decimal/div.rs index 15b8c6b83a8..55cca8d303d 100644 --- a/tests/it/compute/arithmetics/decimal/div.rs +++ b/tests/it/compute/arithmetics/decimal/div.rs @@ -1,7 +1,7 @@ #![allow(clippy::zero_prefixed_literal, clippy::inconsistent_digit_grouping)] use arrow2::array::*; -use arrow2::compute::arithmetics::decimal::div::*; +use arrow2::compute::arithmetics::decimal::{adaptive_div, checked_div, div, saturating_div}; use arrow2::compute::arithmetics::{ArrayCheckedDiv, ArrayDiv}; use arrow2::datatypes::DataType; @@ -31,7 +31,7 @@ fn test_divide_normal() { ]) .to(DataType::Decimal(7, 3)); - let result = div(&a, &b).unwrap(); + let result = div(&a, &b); let expected = PrimitiveArray::from([ Some(1_800i128), Some(5_000i128), @@ -45,19 +45,16 @@ fn test_divide_normal() { assert_eq!(result, expected); // Testing trait - let result = a.div(&b).unwrap(); + let result = a.div(&b); assert_eq!(result, expected); } #[test] +#[should_panic] fn test_divide_decimal_wrong_precision() { let a = PrimitiveArray::from([None]).to(DataType::Decimal(5, 2)); let b = PrimitiveArray::from([None]).to(DataType::Decimal(6, 2)); - let result = div(&a, &b); - - if result.is_ok() { - panic!("Should panic for different precision"); - } + div(&a, &b); } #[test] @@ -65,7 +62,7 @@ fn test_divide_decimal_wrong_precision() { fn test_divide_panic() { let a = PrimitiveArray::from([Some(99999i128)]).to(DataType::Decimal(5, 2)); let b = PrimitiveArray::from([Some(000_01i128)]).to(DataType::Decimal(5, 2)); - let _ = div(&a, &b); + div(&a, &b); } #[test] @@ -90,7 +87,7 @@ fn test_divide_saturating() { ]) .to(DataType::Decimal(7, 3)); - let result = saturating_div(&a, &b).unwrap(); + let result = saturating_div(&a, &b); let expected = PrimitiveArray::from([ Some(1_800i128), Some(5_000i128), @@ -123,7 +120,7 @@ fn test_divide_saturating_overflow() { ]) .to(DataType::Decimal(5, 2)); - let result = saturating_div(&a, &b).unwrap(); + let result = saturating_div(&a, &b); let expected = PrimitiveArray::from([ Some(-99999i128), @@ -159,7 +156,7 @@ fn test_divide_checked() { ]) .to(DataType::Decimal(7, 3)); - let result = div(&a, &b).unwrap(); + let result = div(&a, &b); let expected = PrimitiveArray::from([ Some(1_800i128), Some(5_000i128), @@ -180,13 +177,13 @@ fn test_divide_checked_overflow() { let b = PrimitiveArray::from([Some(000_00i128), None, Some(2_00i128)]).to(DataType::Decimal(5, 2)); - let result = checked_div(&a, &b).unwrap(); + let result = checked_div(&a, &b); let expected = PrimitiveArray::from([None, None, Some(3_00i128)]).to(DataType::Decimal(5, 2)); assert_eq!(result, expected); // Testing trait - let result = a.checked_div(&b).unwrap(); + let result = a.checked_div(&b); assert_eq!(result, expected); } diff --git a/tests/it/compute/arithmetics/decimal/mul.rs b/tests/it/compute/arithmetics/decimal/mul.rs index 6c26d290059..a4b4a71b257 100644 --- a/tests/it/compute/arithmetics/decimal/mul.rs +++ b/tests/it/compute/arithmetics/decimal/mul.rs @@ -1,7 +1,7 @@ #![allow(clippy::zero_prefixed_literal, clippy::inconsistent_digit_grouping)] use arrow2::array::*; -use arrow2::compute::arithmetics::decimal::mul::*; +use arrow2::compute::arithmetics::decimal::{adaptive_mul, checked_mul, mul, saturating_mul}; use arrow2::compute::arithmetics::{ArrayCheckedMul, ArrayMul, ArraySaturatingMul}; use arrow2::datatypes::DataType; @@ -31,7 +31,7 @@ fn test_multiply_normal() { ]) .to(DataType::Decimal(7, 2)); - let result = mul(&a, &b).unwrap(); + let result = mul(&a, &b); let expected = PrimitiveArray::from([ Some(24690_86i128), Some(20_00i128), @@ -45,19 +45,16 @@ fn test_multiply_normal() { assert_eq!(result, expected); // Testing trait - let result = a.mul(&b).unwrap(); + let result = a.mul(&b); assert_eq!(result, expected); } #[test] +#[should_panic] fn test_multiply_decimal_wrong_precision() { let a = PrimitiveArray::from([None]).to(DataType::Decimal(5, 2)); let b = PrimitiveArray::from([None]).to(DataType::Decimal(6, 2)); - let result = mul(&a, &b); - - if result.is_ok() { - panic!("Should panic for different precision"); - } + mul(&a, &b); } #[test] @@ -90,7 +87,7 @@ fn test_multiply_saturating() { ]) .to(DataType::Decimal(7, 2)); - let result = saturating_mul(&a, &b).unwrap(); + let result = saturating_mul(&a, &b); let expected = PrimitiveArray::from([ Some(24690_86i128), Some(20_00i128), @@ -104,7 +101,7 @@ fn test_multiply_saturating() { assert_eq!(result, expected); // Testing trait - let result = a.saturating_mul(&b).unwrap(); + let result = a.saturating_mul(&b); assert_eq!(result, expected); } @@ -125,7 +122,7 @@ fn test_multiply_saturating_overflow() { ]) .to(DataType::Decimal(5, 2)); - let result = saturating_mul(&a, &b).unwrap(); + let result = saturating_mul(&a, &b); let expected = PrimitiveArray::from([ Some(-99999i128), @@ -138,7 +135,7 @@ fn test_multiply_saturating_overflow() { assert_eq!(result, expected); // Testing trait - let result = a.saturating_mul(&b).unwrap(); + let result = a.saturating_mul(&b); assert_eq!(result, expected); } @@ -164,7 +161,7 @@ fn test_multiply_checked() { ]) .to(DataType::Decimal(7, 2)); - let result = checked_mul(&a, &b).unwrap(); + let result = checked_mul(&a, &b); let expected = PrimitiveArray::from([ Some(24690_86i128), Some(20_00i128), @@ -178,7 +175,7 @@ fn test_multiply_checked() { assert_eq!(result, expected); // Testing trait - let result = a.checked_mul(&b).unwrap(); + let result = a.checked_mul(&b); assert_eq!(result, expected); } @@ -186,7 +183,7 @@ fn test_multiply_checked() { fn test_multiply_checked_overflow() { let a = PrimitiveArray::from([Some(99999i128), Some(1_00i128)]).to(DataType::Decimal(5, 2)); let b = PrimitiveArray::from([Some(10000i128), Some(2_00i128)]).to(DataType::Decimal(5, 2)); - let result = checked_mul(&a, &b).unwrap(); + let result = checked_mul(&a, &b); let expected = PrimitiveArray::from([None, Some(2_00i128)]).to(DataType::Decimal(5, 2)); assert_eq!(result, expected); diff --git a/tests/it/compute/arithmetics/decimal/sub.rs b/tests/it/compute/arithmetics/decimal/sub.rs index 467b1d220c6..343149a5646 100644 --- a/tests/it/compute/arithmetics/decimal/sub.rs +++ b/tests/it/compute/arithmetics/decimal/sub.rs @@ -1,7 +1,7 @@ #![allow(clippy::zero_prefixed_literal, clippy::inconsistent_digit_grouping)] use arrow2::array::*; -use arrow2::compute::arithmetics::decimal::sub::*; +use arrow2::compute::arithmetics::decimal::{adaptive_sub, checked_sub, saturating_sub, sub}; use arrow2::compute::arithmetics::{ArrayCheckedSub, ArraySaturatingSub, ArraySub}; use arrow2::datatypes::DataType; @@ -13,26 +13,23 @@ fn test_subtract_normal() { let b = PrimitiveArray::from([Some(22222i128), Some(11100i128), None, Some(11100i128)]) .to(DataType::Decimal(5, 2)); - let result = sub(&a, &b).unwrap(); + let result = sub(&a, &b); let expected = PrimitiveArray::from([Some(-11111i128), Some(11100i128), None, Some(28900i128)]) .to(DataType::Decimal(5, 2)); assert_eq!(result, expected); // Testing trait - let result = a.sub(&b).unwrap(); + let result = a.sub(&b); assert_eq!(result, expected); } #[test] +#[should_panic] fn test_subtract_decimal_wrong_precision() { let a = PrimitiveArray::from([None]).to(DataType::Decimal(5, 2)); let b = PrimitiveArray::from([None]).to(DataType::Decimal(6, 2)); - let result = sub(&a, &b); - - if result.is_ok() { - panic!("Should panic for different precision"); - } + sub(&a, &b); } #[test] @@ -51,14 +48,14 @@ fn test_subtract_saturating() { let b = PrimitiveArray::from([Some(22222i128), Some(11100i128), None, Some(11100i128)]) .to(DataType::Decimal(5, 2)); - let result = saturating_sub(&a, &b).unwrap(); + let result = saturating_sub(&a, &b); let expected = PrimitiveArray::from([Some(-11111i128), Some(11100i128), None, Some(28900i128)]) .to(DataType::Decimal(5, 2)); assert_eq!(result, expected); // Testing trait - let result = a.saturating_sub(&b).unwrap(); + let result = a.saturating_sub(&b); assert_eq!(result, expected); } @@ -79,7 +76,7 @@ fn test_subtract_saturating_overflow() { ]) .to(DataType::Decimal(5, 2)); - let result = saturating_sub(&a, &b).unwrap(); + let result = saturating_sub(&a, &b); let expected = PrimitiveArray::from([ Some(-99999i128), @@ -92,7 +89,7 @@ fn test_subtract_saturating_overflow() { assert_eq!(result, expected); // Testing trait - let result = a.saturating_sub(&b).unwrap(); + let result = a.saturating_sub(&b); assert_eq!(result, expected); } @@ -104,14 +101,14 @@ fn test_subtract_checked() { let b = PrimitiveArray::from([Some(22222i128), Some(11100i128), None, Some(11100i128)]) .to(DataType::Decimal(5, 2)); - let result = checked_sub(&a, &b).unwrap(); + let result = checked_sub(&a, &b); let expected = PrimitiveArray::from([Some(-11111i128), Some(11100i128), None, Some(28900i128)]) .to(DataType::Decimal(5, 2)); assert_eq!(result, expected); // Testing trait - let result = a.checked_sub(&b).unwrap(); + let result = a.checked_sub(&b); assert_eq!(result, expected); } @@ -119,7 +116,7 @@ fn test_subtract_checked() { fn test_subtract_checked_overflow() { let a = PrimitiveArray::from([Some(4i128), Some(-99999i128)]).to(DataType::Decimal(5, 2)); let b = PrimitiveArray::from([Some(2i128), Some(1i128)]).to(DataType::Decimal(5, 2)); - let result = checked_sub(&a, &b).unwrap(); + let result = checked_sub(&a, &b); let expected = PrimitiveArray::from([Some(2i128), None]).to(DataType::Decimal(5, 2)); assert_eq!(result, expected); } diff --git a/tests/it/compute/arithmetics/mod.rs b/tests/it/compute/arithmetics/mod.rs index 00b90bc0dd1..4b5e6a3e241 100644 --- a/tests/it/compute/arithmetics/mod.rs +++ b/tests/it/compute/arithmetics/mod.rs @@ -3,7 +3,7 @@ mod decimal; mod time; use arrow2::array::new_empty_array; -use arrow2::compute::arithmetics::{arithmetic, can_arithmetic, Operator}; +use arrow2::compute::arithmetics::*; use arrow2::datatypes::DataType::*; use arrow2::datatypes::{IntervalUnit, TimeUnit}; @@ -42,27 +42,26 @@ fn consistency() { Duration(TimeUnit::Nanosecond), Interval(IntervalUnit::MonthDayNano), ]; - let operators = vec![ - Operator::Add, - Operator::Divide, - Operator::Subtract, - Operator::Multiply, - Operator::Remainder, - ]; - let cases = datatypes - .clone() - .into_iter() - .zip(operators.into_iter()) - .zip(datatypes.into_iter()); + let cases = datatypes.clone().into_iter().zip(datatypes.into_iter()); - cases.for_each(|((lhs, op), rhs)| { + cases.for_each(|(lhs, rhs)| { let lhs_a = new_empty_array(lhs.clone()); let rhs_a = new_empty_array(rhs.clone()); - if can_arithmetic(&lhs, op, &rhs) { - assert!(arithmetic(lhs_a.as_ref(), op, rhs_a.as_ref()).is_ok()); - } else { - assert!(arithmetic(lhs_a.as_ref(), op, rhs_a.as_ref()).is_err()); + if can_add(&lhs, &rhs) { + add(lhs_a.as_ref(), rhs_a.as_ref()); + } + if can_sub(&lhs, &rhs) { + sub(lhs_a.as_ref(), rhs_a.as_ref()); + } + if can_mul(&lhs, &rhs) { + mul(lhs_a.as_ref(), rhs_a.as_ref()); + } + if can_div(&lhs, &rhs) { + div(lhs_a.as_ref(), rhs_a.as_ref()); + } + if can_rem(&lhs, &rhs) { + rem(lhs_a.as_ref(), rhs_a.as_ref()); } }); } diff --git a/tests/it/compute/arithmetics/time.rs b/tests/it/compute/arithmetics/time.rs index e4462198f3c..0df9416bd5c 100644 --- a/tests/it/compute/arithmetics/time.rs +++ b/tests/it/compute/arithmetics/time.rs @@ -12,7 +12,7 @@ fn test_adding_timestamp() { let duration = PrimitiveArray::from([Some(10i64), Some(20i64), None, Some(30i64)]) .to(DataType::Duration(TimeUnit::Second)); - let result = add_duration(×tamp, &duration).unwrap(); + let result = add_duration(×tamp, &duration); let expected = PrimitiveArray::from([Some(100010i64), Some(200020i64), None, Some(300030i64)]).to( DataType::Timestamp(TimeUnit::Second, Some("America/New_York".to_string())), @@ -36,7 +36,7 @@ fn test_adding_duration_different_scale() { let duration = PrimitiveArray::from([Some(10_000i64), Some(20_000i64), None, Some(30_000i64)]) .to(DataType::Duration(TimeUnit::Millisecond)); - let result = add_duration(×tamp, &duration).unwrap(); + let result = add_duration(×tamp, &duration); assert_eq!(result, expected); // Testing duration in nanoseconds. @@ -51,7 +51,7 @@ fn test_adding_duration_different_scale() { ]) .to(DataType::Duration(TimeUnit::Nanosecond)); - let result = add_duration(×tamp, &duration).unwrap(); + let result = add_duration(×tamp, &duration); assert_eq!(result, expected); } @@ -67,7 +67,7 @@ fn test_adding_subtract_timestamps_scale() { DataType::Timestamp(TimeUnit::Millisecond, Some("America/New_York".to_string())), ); - let result = add_duration(×tamp, &duration).unwrap(); + let result = add_duration(×tamp, &duration); assert_eq!(result, expected); let timestamp = PrimitiveArray::from([Some(10i64), Some(20i64), None, Some(30i64)]).to( @@ -87,7 +87,7 @@ fn test_adding_subtract_timestamps_scale() { Some("America/New_York".to_string()), )); - let result = add_duration(×tamp, &duration).unwrap(); + let result = add_duration(×tamp, &duration); assert_eq!(result, expected); } @@ -101,7 +101,7 @@ fn test_subtract_timestamp() { let duration = PrimitiveArray::from([Some(10i64), Some(20i64), None, Some(30i64)]) .to(DataType::Duration(TimeUnit::Second)); - let result = subtract_duration(×tamp, &duration).unwrap(); + let result = subtract_duration(×tamp, &duration); let expected = PrimitiveArray::from([Some(99990i64), Some(199980i64), None, Some(299970i64)]).to( DataType::Timestamp(TimeUnit::Second, Some("America/New_York".to_string())), @@ -125,7 +125,7 @@ fn test_subtracting_duration_different_scale() { let duration = PrimitiveArray::from([Some(10_000i64), Some(20_000i64), None, Some(30_000i64)]) .to(DataType::Duration(TimeUnit::Millisecond)); - let result = subtract_duration(×tamp, &duration).unwrap(); + let result = subtract_duration(×tamp, &duration); assert_eq!(result, expected); // Testing duration in nanoseconds. @@ -140,7 +140,7 @@ fn test_subtracting_duration_different_scale() { ]) .to(DataType::Duration(TimeUnit::Nanosecond)); - let result = subtract_duration(×tamp, &duration).unwrap(); + let result = subtract_duration(×tamp, &duration); assert_eq!(result, expected); } @@ -157,7 +157,7 @@ fn test_subtracting_subtract_timestamps_scale() { DataType::Timestamp(TimeUnit::Millisecond, Some("America/New_York".to_string())), ); - let result = subtract_duration(×tamp, &duration).unwrap(); + let result = subtract_duration(×tamp, &duration); assert_eq!(result, expected); let timestamp = PrimitiveArray::from([Some(10i64), Some(20i64), None, Some(30i64)]).to( @@ -177,7 +177,7 @@ fn test_subtracting_subtract_timestamps_scale() { Some("America/New_York".to_string()), )); - let result = subtract_duration(×tamp, &duration).unwrap(); + let result = subtract_duration(×tamp, &duration); assert_eq!(result, expected); } @@ -229,7 +229,7 @@ fn test_adding_to_time() { let time_32 = PrimitiveArray::from([Some(100000i32), Some(200000i32), None, Some(300000i32)]) .to(DataType::Time32(TimeUnit::Second)); - let result = add_duration(&time_32, &duration).unwrap(); + let result = add_duration(&time_32, &duration); let expected = PrimitiveArray::from([Some(100010i32), Some(200020i32), None, Some(300030i32)]) .to(DataType::Time32(TimeUnit::Second)); @@ -245,7 +245,7 @@ fn test_subtract_to_time() { let time_32 = PrimitiveArray::from([Some(100000i32), Some(200000i32), None, Some(300000i32)]) .to(DataType::Time32(TimeUnit::Second)); - let result = subtract_duration(&time_32, &duration).unwrap(); + let result = subtract_duration(&time_32, &duration); let expected = PrimitiveArray::from([Some(99990i32), Some(199980i32), None, Some(299970i32)]) .to(DataType::Time32(TimeUnit::Second)); @@ -266,14 +266,14 @@ fn test_date32() { PrimitiveArray::from([Some(100_000i32), Some(100_000i32), None, Some(100_000i32)]) .to(DataType::Date32); - let result = add_duration(&date_32, &duration).unwrap(); + let result = add_duration(&date_32, &duration); let expected = PrimitiveArray::from([Some(100_001i32), Some(100_010i32), None, Some(100_100i32)]) .to(DataType::Date32); assert_eq!(result, expected); - let result = subtract_duration(&date_32, &duration).unwrap(); + let result = subtract_duration(&date_32, &duration); let expected = PrimitiveArray::from([Some(99_999i32), Some(99_990i32), None, Some(99_900i32)]) .to(DataType::Date32); @@ -294,14 +294,14 @@ fn test_date64() { PrimitiveArray::from([Some(100_000i64), Some(100_000i64), None, Some(100_000i64)]) .to(DataType::Date64); - let result = add_duration(&date_64, &duration).unwrap(); + let result = add_duration(&date_64, &duration); let expected = PrimitiveArray::from([Some(100_010i64), Some(100_100i64), None, Some(101_000i64)]) .to(DataType::Date64); assert_eq!(result, expected); - let result = subtract_duration(&date_64, &duration).unwrap(); + let result = subtract_duration(&date_64, &duration); let expected = PrimitiveArray::from([Some(99_990i64), Some(99_900i64), None, Some(99_000i64)]) .to(DataType::Date64); diff --git a/tests/it/compute/bitwise.rs b/tests/it/compute/bitwise.rs index 92b8b47b4ab..3d44e58f219 100644 --- a/tests/it/compute/bitwise.rs +++ b/tests/it/compute/bitwise.rs @@ -5,7 +5,7 @@ use arrow2::compute::bitwise::*; fn test_xor() { let a = Int32Array::from(&[Some(2), Some(4), Some(6), Some(7)]); let b = Int32Array::from(&[None, Some(6), Some(9), Some(7)]); - let result = xor(&a, &b).unwrap(); + let result = xor(&a, &b); let expected = Int32Array::from(&[None, Some(2), Some(15), Some(0)]); assert_eq!(result, expected); @@ -15,7 +15,7 @@ fn test_xor() { fn test_and() { let a = Int32Array::from(&[Some(1), Some(2), Some(15)]); let b = Int32Array::from(&[None, Some(2), Some(6)]); - let result = and(&a, &b).unwrap(); + let result = and(&a, &b); let expected = Int32Array::from(&[None, Some(2), Some(6)]); assert_eq!(result, expected); @@ -25,7 +25,7 @@ fn test_and() { fn test_or() { let a = Int32Array::from(&[Some(1), Some(2), Some(0)]); let b = Int32Array::from(&[None, Some(2), Some(0)]); - let result = or(&a, &b).unwrap(); + let result = or(&a, &b); let expected = Int32Array::from(&[None, Some(2), Some(0)]); assert_eq!(result, expected);