This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new fb5874388f Remove redundant trait bounds on `ArrowNativeTypeOp` (#9614)
fb5874388f is described below
commit fb5874388f7d2c7f210293d734beebd0068e5a2f
Author: Alexandre Crayssac <[email protected]>
AuthorDate: Mon Apr 6 21:01:48 2026 +0200
Remove redundant trait bounds on `ArrowNativeTypeOp` (#9614)
# Which issue does this PR close?
None.
# Rationale for this change
While reading the codebase I spotted some redundant trait bounds on
`ArrowNativeTypeOp`.
# What changes are included in this PR?
Remove some trait bounds on `ArrowNativeTypeOp`.
# Are these changes tested?
It compiles so I guess it's enough.
# Are there any user-facing changes?
Nope.
Co-authored-by: alexandreyc <[email protected]>
---
arrow-arith/src/aggregate.rs | 57 +++++++++++++-----------------------------
arrow-arith/src/arithmetic.rs | 6 +----
arrow-cast/src/cast/decimal.rs | 2 +-
arrow-cast/src/cast/mod.rs | 2 +-
arrow-ord/src/ord.rs | 5 +---
5 files changed, 22 insertions(+), 50 deletions(-)
diff --git a/arrow-arith/src/aggregate.rs b/arrow-arith/src/aggregate.rs
index 59792d0c5b..8745c779ce 100644
--- a/arrow-arith/src/aggregate.rs
+++ b/arrow-arith/src/aggregate.rs
@@ -20,7 +20,7 @@
use arrow_array::cast::*;
use arrow_array::iterator::ArrayIter;
use arrow_array::*;
-use arrow_buffer::{ArrowNativeType, NullBuffer};
+use arrow_buffer::NullBuffer;
use arrow_data::bit_iterator::try_for_each_valid_idx;
use arrow_schema::*;
use std::borrow::BorrowMut;
@@ -541,11 +541,9 @@ pub fn min_string_view(array: &StringViewArray) ->
Option<&str> {
///
/// This doesn't detect overflow. Once overflowing, the result will wrap
around.
/// For an overflow-checking variant, use [`sum_array_checked`] instead.
-pub fn sum_array<T, A: ArrayAccessor<Item = T::Native>>(array: A) ->
Option<T::Native>
-where
- T: ArrowNumericType,
- T::Native: ArrowNativeTypeOp,
-{
+pub fn sum_array<T: ArrowNumericType, A: ArrayAccessor<Item = T::Native>>(
+ array: A,
+) -> Option<T::Native> {
match array.data_type() {
DataType::Dictionary(_, _) => {
let null_count = array.null_count();
@@ -583,13 +581,9 @@ where
/// use [`sum_array`] instead.
/// Additionally returns an `Err` on run-end-encoded arrays with a provided
/// values type parameter that is incorrect.
-pub fn sum_array_checked<T, A: ArrayAccessor<Item = T::Native>>(
+pub fn sum_array_checked<T: ArrowNumericType, A: ArrayAccessor<Item =
T::Native>>(
array: A,
-) -> Result<Option<T::Native>, ArrowError>
-where
- T: ArrowNumericType,
- T::Native: ArrowNativeTypeOp,
-{
+) -> Result<Option<T::Native>, ArrowError> {
match array.data_type() {
DataType::Dictionary(_, _) => {
let null_count = array.null_count();
@@ -717,21 +711,17 @@ mod ree {
/// Returns the min of values in the array of `ArrowNumericType` type, or
dictionary
/// array with value of `ArrowNumericType` type.
-pub fn min_array<T, A: ArrayAccessor<Item = T::Native>>(array: A) ->
Option<T::Native>
-where
- T: ArrowNumericType,
- T::Native: ArrowNativeType,
-{
+pub fn min_array<T: ArrowNumericType, A: ArrayAccessor<Item = T::Native>>(
+ array: A,
+) -> Option<T::Native> {
min_max_array_helper::<T, A, _, _>(array, |a, b| a.is_gt(*b), min)
}
/// Returns the max of values in the array of `ArrowNumericType` type, or
dictionary
/// array with value of `ArrowNumericType` type.
-pub fn max_array<T, A: ArrayAccessor<Item = T::Native>>(array: A) ->
Option<T::Native>
-where
- T: ArrowNumericType,
- T::Native: ArrowNativeTypeOp,
-{
+pub fn max_array<T: ArrowNumericType, A: ArrayAccessor<Item = T::Native>>(
+ array: A,
+) -> Option<T::Native> {
min_max_array_helper::<T, A, _, _>(array, |a, b| a.is_lt(*b), max)
}
@@ -874,11 +864,9 @@ pub fn bool_or(array: &BooleanArray) -> Option<bool> {
///
/// This detects overflow and returns an `Err` for that. For an
non-overflow-checking variant,
/// use [`sum`] instead.
-pub fn sum_checked<T>(array: &PrimitiveArray<T>) -> Result<Option<T::Native>,
ArrowError>
-where
- T: ArrowNumericType,
- T::Native: ArrowNativeTypeOp,
-{
+pub fn sum_checked<T: ArrowNumericType>(
+ array: &PrimitiveArray<T>,
+) -> Result<Option<T::Native>, ArrowError> {
let null_count = array.null_count();
if null_count == array.len() {
@@ -922,10 +910,7 @@ where
///
/// This doesn't detect overflow in release mode by default. Once overflowing,
the result will
/// wrap around. For an overflow-checking variant, use [`sum_checked`] instead.
-pub fn sum<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native>
-where
- T::Native: ArrowNativeTypeOp,
-{
+pub fn sum<T: ArrowNumericType>(array: &PrimitiveArray<T>) ->
Option<T::Native> {
aggregate::<T::Native, T, SumAccumulator<T::Native>>(array)
}
@@ -940,10 +925,7 @@ where
/// let result = min(&array);
/// assert_eq!(result, Some(2));
/// ```
-pub fn min<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native>
-where
- T::Native: PartialOrd,
-{
+pub fn min<T: ArrowNumericType>(array: &PrimitiveArray<T>) ->
Option<T::Native> {
aggregate::<T::Native, T, MinAccumulator<T::Native>>(array)
}
@@ -958,10 +940,7 @@ where
/// let result = max(&array);
/// assert_eq!(result, Some(8));
/// ```
-pub fn max<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native>
-where
- T::Native: PartialOrd,
-{
+pub fn max<T: ArrowNumericType>(array: &PrimitiveArray<T>) ->
Option<T::Native> {
aggregate::<T::Native, T, MaxAccumulator<T::Native>>(array)
}
diff --git a/arrow-arith/src/arithmetic.rs b/arrow-arith/src/arithmetic.rs
index 27efed6fcd..e8539c64b1 100644
--- a/arrow-arith/src/arithmetic.rs
+++ b/arrow-arith/src/arithmetic.rs
@@ -170,11 +170,7 @@ pub fn multiply_fixed_point(
}
/// Divide a decimal native value by given divisor and round the result.
-fn divide_and_round<I>(input: I::Native, div: I::Native) -> I::Native
-where
- I: DecimalType,
- I::Native: ArrowNativeTypeOp,
-{
+fn divide_and_round<I: DecimalType>(input: I::Native, div: I::Native) ->
I::Native {
let d = input.div_wrapping(div);
let r = input.mod_wrapping(div);
diff --git a/arrow-cast/src/cast/decimal.rs b/arrow-cast/src/cast/decimal.rs
index f8fe06a573..3553f2b6a7 100644
--- a/arrow-cast/src/cast/decimal.rs
+++ b/arrow-cast/src/cast/decimal.rs
@@ -812,7 +812,7 @@ where
T: ArrowPrimitiveType,
<T as ArrowPrimitiveType>::Native: NumCast,
D: DecimalType + ArrowPrimitiveType,
- <D as ArrowPrimitiveType>::Native: ArrowNativeTypeOp + ToPrimitive,
+ <D as ArrowPrimitiveType>::Native: ToPrimitive,
{
let array = array.as_primitive::<D>();
diff --git a/arrow-cast/src/cast/mod.rs b/arrow-cast/src/cast/mod.rs
index a584c39fa6..f152f557e2 100644
--- a/arrow-cast/src/cast/mod.rs
+++ b/arrow-cast/src/cast/mod.rs
@@ -2298,7 +2298,7 @@ fn cast_from_decimal<D, F>(
) -> Result<ArrayRef, ArrowError>
where
D: DecimalType + ArrowPrimitiveType,
- <D as ArrowPrimitiveType>::Native: ArrowNativeTypeOp + ToPrimitive,
+ <D as ArrowPrimitiveType>::Native: ToPrimitive,
F: Fn(D::Native) -> f64,
{
use DataType::*;
diff --git a/arrow-ord/src/ord.rs b/arrow-ord/src/ord.rs
index 5951a58788..51ae3c4d76 100644
--- a/arrow-ord/src/ord.rs
+++ b/arrow-ord/src/ord.rs
@@ -114,10 +114,7 @@ fn compare_primitive<T: ArrowPrimitiveType>(
left: &dyn Array,
right: &dyn Array,
opts: SortOptions,
-) -> DynComparator
-where
- T::Native: ArrowNativeTypeOp,
-{
+) -> DynComparator {
let left = left.as_primitive::<T>();
let right = right.as_primitive::<T>();
let l_values = left.values().clone();