You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2024/02/08 14:39:58 UTC
(arrow-rs) 01/01: Fix latest clippy lints
This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch clippy-lints
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
commit 68e5ec432f77e50bbbce2fc7133b21e07a2f5d96
Author: Raphael Taylor-Davies <r....@googlemail.com>
AuthorDate: Thu Feb 8 14:39:41 2024 +0000
Fix latest clippy lints
---
arrow-arith/src/arity.rs | 111 +++++++++++++++----------------
arrow-array/src/array/primitive_array.rs | 81 +++++++++++-----------
arrow-row/src/variable.rs | 2 +-
3 files changed, 97 insertions(+), 97 deletions(-)
diff --git a/arrow-arith/src/arity.rs b/arrow-arith/src/arity.rs
index ff8b82a5d9..4488be7dbd 100644
--- a/arrow-arith/src/arity.rs
+++ b/arrow-arith/src/arity.rs
@@ -28,10 +28,10 @@ use std::sync::Arc;
/// See [`PrimitiveArray::unary`]
pub fn unary<I, F, O>(array: &PrimitiveArray<I>, op: F) -> PrimitiveArray<O>
-where
- I: ArrowPrimitiveType,
- O: ArrowPrimitiveType,
- F: Fn(I::Native) -> O::Native,
+ where
+ I: ArrowPrimitiveType,
+ O: ArrowPrimitiveType,
+ F: Fn(I::Native) -> O::Native,
{
array.unary(op)
}
@@ -41,19 +41,19 @@ pub fn unary_mut<I, F>(
array: PrimitiveArray<I>,
op: F,
) -> Result<PrimitiveArray<I>, PrimitiveArray<I>>
-where
- I: ArrowPrimitiveType,
- F: Fn(I::Native) -> I::Native,
+ where
+ I: ArrowPrimitiveType,
+ F: Fn(I::Native) -> I::Native,
{
array.unary_mut(op)
}
/// See [`PrimitiveArray::try_unary`]
pub fn try_unary<I, F, O>(array: &PrimitiveArray<I>, op: F) -> Result<PrimitiveArray<O>, ArrowError>
-where
- I: ArrowPrimitiveType,
- O: ArrowPrimitiveType,
- F: Fn(I::Native) -> Result<O::Native, ArrowError>,
+ where
+ I: ArrowPrimitiveType,
+ O: ArrowPrimitiveType,
+ F: Fn(I::Native) -> Result<O::Native, ArrowError>,
{
array.try_unary(op)
}
@@ -63,19 +63,19 @@ pub fn try_unary_mut<I, F>(
array: PrimitiveArray<I>,
op: F,
) -> Result<Result<PrimitiveArray<I>, ArrowError>, PrimitiveArray<I>>
-where
- I: ArrowPrimitiveType,
- F: Fn(I::Native) -> Result<I::Native, ArrowError>,
+ where
+ I: ArrowPrimitiveType,
+ F: Fn(I::Native) -> Result<I::Native, ArrowError>,
{
array.try_unary_mut(op)
}
/// A helper function that applies an infallible unary function to a dictionary array with primitive value type.
fn unary_dict<K, F, T>(array: &DictionaryArray<K>, op: F) -> Result<ArrayRef, ArrowError>
-where
- K: ArrowDictionaryKeyType + ArrowNumericType,
- T: ArrowPrimitiveType,
- F: Fn(T::Native) -> T::Native,
+ where
+ K: ArrowDictionaryKeyType + ArrowNumericType,
+ T: ArrowPrimitiveType,
+ F: Fn(T::Native) -> T::Native,
{
let dict_values = array.values().as_any().downcast_ref().unwrap();
let values = unary::<T, F, T>(dict_values, op);
@@ -84,10 +84,10 @@ where
/// A helper function that applies a fallible unary function to a dictionary array with primitive value type.
fn try_unary_dict<K, F, T>(array: &DictionaryArray<K>, op: F) -> Result<ArrayRef, ArrowError>
-where
- K: ArrowDictionaryKeyType + ArrowNumericType,
- T: ArrowPrimitiveType,
- F: Fn(T::Native) -> Result<T::Native, ArrowError>,
+ where
+ K: ArrowDictionaryKeyType + ArrowNumericType,
+ T: ArrowPrimitiveType,
+ F: Fn(T::Native) -> Result<T::Native, ArrowError>,
{
if !PrimitiveArray::<T>::is_compatible(&array.value_type()) {
return Err(ArrowError::CastError(format!(
@@ -105,9 +105,9 @@ where
/// Applies an infallible unary function to an array with primitive values.
#[deprecated(note = "Use arrow_array::AnyDictionaryArray")]
pub fn unary_dyn<F, T>(array: &dyn Array, op: F) -> Result<ArrayRef, ArrowError>
-where
- T: ArrowPrimitiveType,
- F: Fn(T::Native) -> T::Native,
+ where
+ T: ArrowPrimitiveType,
+ F: Fn(T::Native) -> T::Native,
{
downcast_dictionary_array! {
array => unary_dict::<_, F, T>(array, op),
@@ -131,9 +131,9 @@ where
/// Applies a fallible unary function to an array with primitive values.
#[deprecated(note = "Use arrow_array::AnyDictionaryArray")]
pub fn try_unary_dyn<F, T>(array: &dyn Array, op: F) -> Result<ArrayRef, ArrowError>
-where
- T: ArrowPrimitiveType,
- F: Fn(T::Native) -> Result<T::Native, ArrowError>,
+ where
+ T: ArrowPrimitiveType,
+ F: Fn(T::Native) -> Result<T::Native, ArrowError>,
{
downcast_dictionary_array! {
array => if array.values().data_type() == &T::DATA_TYPE {
@@ -178,11 +178,11 @@ pub fn binary<A, B, F, O>(
b: &PrimitiveArray<B>,
op: F,
) -> Result<PrimitiveArray<O>, ArrowError>
-where
- A: ArrowPrimitiveType,
- B: ArrowPrimitiveType,
- O: ArrowPrimitiveType,
- F: Fn(A::Native, B::Native) -> O::Native,
+ where
+ A: ArrowPrimitiveType,
+ B: ArrowPrimitiveType,
+ O: ArrowPrimitiveType,
+ F: Fn(A::Native, B::Native) -> O::Native,
{
if a.len() != b.len() {
return Err(ArrowError::ComputeError(
@@ -228,9 +228,9 @@ pub fn binary_mut<T, F>(
b: &PrimitiveArray<T>,
op: F,
) -> Result<Result<PrimitiveArray<T>, ArrowError>, PrimitiveArray<T>>
-where
- T: ArrowPrimitiveType,
- F: Fn(T::Native, T::Native) -> T::Native,
+ where
+ T: ArrowPrimitiveType,
+ F: Fn(T::Native, T::Native) -> T::Native,
{
if a.len() != b.len() {
return Ok(Err(ArrowError::ComputeError(
@@ -275,9 +275,9 @@ pub fn try_binary<A: ArrayAccessor, B: ArrayAccessor, F, O>(
b: B,
op: F,
) -> Result<PrimitiveArray<O>, ArrowError>
-where
- O: ArrowPrimitiveType,
- F: Fn(A::Item, B::Item) -> Result<O::Native, ArrowError>,
+ where
+ O: ArrowPrimitiveType,
+ F: Fn(A::Item, B::Item) -> Result<O::Native, ArrowError>,
{
if a.len() != b.len() {
return Err(ArrowError::ComputeError(
@@ -331,9 +331,9 @@ pub fn try_binary_mut<T, F>(
b: &PrimitiveArray<T>,
op: F,
) -> Result<Result<PrimitiveArray<T>, ArrowError>, PrimitiveArray<T>>
-where
- T: ArrowPrimitiveType,
- F: Fn(T::Native, T::Native) -> Result<T::Native, ArrowError>,
+ where
+ T: ArrowPrimitiveType,
+ F: Fn(T::Native, T::Native) -> Result<T::Native, ArrowError>,
{
if a.len() != b.len() {
return Ok(Err(ArrowError::ComputeError(
@@ -358,17 +358,16 @@ where
let slice = builder.values_slice_mut();
- match nulls.try_for_each_valid_idx(|idx| {
+ let r = nulls.try_for_each_valid_idx(|idx| {
unsafe {
*slice.get_unchecked_mut(idx) =
op(*slice.get_unchecked(idx), b.value_unchecked(idx))?
};
Ok::<_, ArrowError>(())
- }) {
- Ok(_) => {}
- Err(err) => return Ok(Err(err)),
- };
-
+ });
+ if let Err(err) = r {
+ return Ok(Err(err));
+ }
let array_builder = builder.finish().into_data().into_builder();
let array_data = unsafe { array_builder.nulls(Some(nulls)).build_unchecked() };
Ok(Ok(PrimitiveArray::<T>::from(array_data)))
@@ -383,9 +382,9 @@ fn try_binary_no_nulls<A: ArrayAccessor, B: ArrayAccessor, F, O>(
b: B,
op: F,
) -> Result<PrimitiveArray<O>, ArrowError>
-where
- O: ArrowPrimitiveType,
- F: Fn(A::Item, B::Item) -> Result<O::Native, ArrowError>,
+ where
+ O: ArrowPrimitiveType,
+ F: Fn(A::Item, B::Item) -> Result<O::Native, ArrowError>,
{
let mut buffer = MutableBuffer::new(len * O::get_byte_width());
for idx in 0..len {
@@ -404,9 +403,9 @@ fn try_binary_no_nulls_mut<T, F>(
b: &PrimitiveArray<T>,
op: F,
) -> Result<Result<PrimitiveArray<T>, ArrowError>, PrimitiveArray<T>>
-where
- T: ArrowPrimitiveType,
- F: Fn(T::Native, T::Native) -> Result<T::Native, ArrowError>,
+ where
+ T: ArrowPrimitiveType,
+ F: Fn(T::Native, T::Native) -> Result<T::Native, ArrowError>,
{
let mut builder = a.into_builder()?;
let slice = builder.values_slice_mut();
@@ -523,8 +522,8 @@ mod tests {
Ok(l + r)
}
})
- .unwrap()
- .expect_err("should got error");
+ .unwrap()
+ .expect_err("should got error");
}
#[test]
diff --git a/arrow-array/src/array/primitive_array.rs b/arrow-array/src/array/primitive_array.rs
index a6d5c22772..d866f0ceb6 100644
--- a/arrow-array/src/array/primitive_array.rs
+++ b/arrow-array/src/array/primitive_array.rs
@@ -658,7 +658,7 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
}
/// Creates a PrimitiveArray based on an iterator of values without nulls
- pub fn from_iter_values<I: IntoIterator<Item = T::Native>>(iter: I) -> Self {
+ pub fn from_iter_values<I: IntoIterator<Item=T::Native>>(iter: I) -> Self {
let val_buf: Buffer = iter.into_iter().collect();
let len = val_buf.len() / std::mem::size_of::<T::Native>();
Self {
@@ -679,8 +679,8 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
/// Returns an iterator that returns the values of `array.value(i)` for an iterator with each element `i`
pub fn take_iter<'a>(
&'a self,
- indexes: impl Iterator<Item = Option<usize>> + 'a,
- ) -> impl Iterator<Item = Option<T::Native>> + 'a {
+ indexes: impl Iterator<Item=Option<usize>> + 'a,
+ ) -> impl Iterator<Item=Option<T::Native>> + 'a {
indexes.map(|opt_index| opt_index.map(|index| self.value(index)))
}
@@ -690,8 +690,8 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
/// caller must ensure that the offsets in the iterator are less than the array len()
pub unsafe fn take_iter_unchecked<'a>(
&'a self,
- indexes: impl Iterator<Item = Option<usize>> + 'a,
- ) -> impl Iterator<Item = Option<T::Native>> + 'a {
+ indexes: impl Iterator<Item=Option<usize>> + 'a,
+ ) -> impl Iterator<Item=Option<T::Native>> + 'a {
indexes.map(|opt_index| opt_index.map(|index| self.value_unchecked(index)))
}
@@ -722,8 +722,8 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
/// let b: TimestampNanosecondArray = a.reinterpret_cast();
/// ```
pub fn reinterpret_cast<K>(&self) -> PrimitiveArray<K>
- where
- K: ArrowPrimitiveType<Native = T::Native>,
+ where
+ K: ArrowPrimitiveType<Native=T::Native>,
{
let d = self.to_data().into_builder().data_type(K::DATA_TYPE);
@@ -751,9 +751,9 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
/// # }
/// ```
pub fn unary<F, O>(&self, op: F) -> PrimitiveArray<O>
- where
- O: ArrowPrimitiveType,
- F: Fn(T::Native) -> O::Native,
+ where
+ O: ArrowPrimitiveType,
+ F: Fn(T::Native) -> O::Native,
{
let nulls = self.nulls().cloned();
let values = self.values().iter().map(|v| op(*v));
@@ -785,8 +785,8 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
/// # }
/// ```
pub fn unary_mut<F>(self, op: F) -> Result<PrimitiveArray<T>, PrimitiveArray<T>>
- where
- F: Fn(T::Native) -> T::Native,
+ where
+ F: Fn(T::Native) -> T::Native,
{
let mut builder = self.into_builder()?;
builder
@@ -804,9 +804,9 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
///
/// Note: LLVM is currently unable to effectively vectorize fallible operations
pub fn try_unary<F, O, E>(&self, op: F) -> Result<PrimitiveArray<O>, E>
- where
- O: ArrowPrimitiveType,
- F: Fn(T::Native) -> Result<O::Native, E>,
+ where
+ O: ArrowPrimitiveType,
+ F: Fn(T::Native) -> Result<O::Native, E>,
{
let len = self.len();
@@ -847,8 +847,8 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
self,
op: F,
) -> Result<Result<PrimitiveArray<T>, E>, PrimitiveArray<T>>
- where
- F: Fn(T::Native) -> Result<T::Native, E>,
+ where
+ F: Fn(T::Native) -> Result<T::Native, E>,
{
let len = self.len();
let null_count = self.null_count();
@@ -856,13 +856,14 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
let (slice, null_buffer) = builder.slices_mut();
- match try_for_each_valid_idx(len, 0, null_count, null_buffer.as_deref(), |idx| {
+ let r = try_for_each_valid_idx(len, 0, null_count, null_buffer.as_deref(), |idx| {
unsafe { *slice.get_unchecked_mut(idx) = op(*slice.get_unchecked(idx))? };
Ok::<_, E>(())
- }) {
- Ok(_) => {}
- Err(err) => return Ok(Err(err)),
- };
+ });
+
+ if let Err(err) = r {
+ return Ok(Err(err));
+ }
Ok(Ok(builder.finish()))
}
@@ -875,9 +876,9 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
///
/// Note: LLVM is currently unable to effectively vectorize fallible operations
pub fn unary_opt<F, O>(&self, op: F) -> PrimitiveArray<O>
- where
- O: ArrowPrimitiveType,
- F: Fn(T::Native) -> Option<O::Native>,
+ where
+ O: ArrowPrimitiveType,
+ F: Fn(T::Native) -> Option<O::Native>,
{
let len = self.len();
let (nulls, null_count, offset) = match self.nulls() {
@@ -1048,8 +1049,8 @@ impl<'a, T: ArrowPrimitiveType> ArrayAccessor for &'a PrimitiveArray<T> {
}
impl<T: ArrowTemporalType> PrimitiveArray<T>
-where
- i64: From<T::Native>,
+ where
+ i64: From<T::Native>,
{
/// Returns value as a chrono `NaiveDateTime`, handling time resolution
///
@@ -1208,7 +1209,7 @@ impl<T: ArrowPrimitiveType> From<&Option<<T as ArrowPrimitiveType>::Native>> for
}
impl<T: ArrowPrimitiveType, Ptr: Into<NativeAdapter<T>>> FromIterator<Ptr> for PrimitiveArray<T> {
- fn from_iter<I: IntoIterator<Item = Ptr>>(iter: I) -> Self {
+ fn from_iter<I: IntoIterator<Item=Ptr>>(iter: I) -> Self {
let iter = iter.into_iter();
let (lower, _) = iter.size_hint();
@@ -1253,9 +1254,9 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
/// I.e. that `size_hint().1` correctly reports its length.
#[inline]
pub unsafe fn from_trusted_len_iter<I, P>(iter: I) -> Self
- where
- P: std::borrow::Borrow<Option<<T as ArrowPrimitiveType>::Native>>,
- I: IntoIterator<Item = P>,
+ where
+ P: std::borrow::Borrow<Option<<T as ArrowPrimitiveType>::Native>>,
+ I: IntoIterator<Item=P>,
{
let iterator = iter.into_iter();
let (_, upper) = iterator.size_hint();
@@ -1329,8 +1330,8 @@ impl<T: ArrowTimestampType> PrimitiveArray<T> {
/// Construct a timestamp array from a vec of i64 values and an optional timezone
#[deprecated(note = "Use with_timezone_opt instead")]
pub fn from_vec(data: Vec<i64>, timezone: Option<String>) -> Self
- where
- Self: From<Vec<i64>>,
+ where
+ Self: From<Vec<i64>>,
{
Self::from(data).with_timezone_opt(timezone)
}
@@ -1338,8 +1339,8 @@ impl<T: ArrowTimestampType> PrimitiveArray<T> {
/// Construct a timestamp array from a vec of `Option<i64>` values and an optional timezone
#[deprecated(note = "Use with_timezone_opt instead")]
pub fn from_opt_vec(data: Vec<Option<i64>>, timezone: Option<String>) -> Self
- where
- Self: From<Vec<Option<i64>>>,
+ where
+ Self: From<Vec<Option<i64>>>,
{
Self::from(data).with_timezone_opt(timezone)
}
@@ -1917,7 +1918,7 @@ mod tests {
1667717999000,
1667718000000,
])
- .with_timezone("America/Denver".to_string());
+ .with_timezone("America/Denver".to_string());
assert_eq!(
"PrimitiveArray<Timestamp(Millisecond, Some(\"America/Denver\"))>\n[\n 2022-03-13T01:59:59-07:00,\n 2022-03-13T03:00:00-06:00,\n 2022-11-06T00:59:59-06:00,\n 2022-11-06T01:00:00-06:00,\n]",
format!("{:?}", arr)
@@ -2065,7 +2066,7 @@ mod tests {
#[test]
#[should_panic(
- expected = "Trying to access an element at index 4 from a PrimitiveArray of length 3"
+ expected = "Trying to access an element at index 4 from a PrimitiveArray of length 3"
)]
fn test_string_array_get_value_index_out_of_bound() {
let array: Int8Array = [10_i8, 11, 12].into_iter().collect();
@@ -2254,7 +2255,7 @@ mod tests {
#[test]
#[should_panic(
- expected = "-123223423432432 is too small to store in a Decimal128 of precision 5. Min is -99999"
+ expected = "-123223423432432 is too small to store in a Decimal128 of precision 5. Min is -99999"
)]
fn test_decimal_array_with_precision_and_scale_out_of_range() {
let arr = Decimal128Array::from_iter_values([12345, 456, 7890, -123223423432432])
@@ -2366,7 +2367,7 @@ mod tests {
#[test]
#[should_panic(
- expected = "Trying to access an element at index 4 from a PrimitiveArray of length 3"
+ expected = "Trying to access an element at index 4 from a PrimitiveArray of length 3"
)]
fn test_fixed_size_binary_array_get_value_index_out_of_bound() {
let array = Decimal128Array::from(vec![-100, 0, 101]);
@@ -2442,7 +2443,7 @@ mod tests {
#[test]
#[should_panic(
- expected = "PrimitiveArray expected data type Interval(MonthDayNano) got Interval(DayTime)"
+ expected = "PrimitiveArray expected data type Interval(MonthDayNano) got Interval(DayTime)"
)]
fn test_invalid_interval_type() {
let array = IntervalDayTimeArray::from(vec![1, 2, 3]);
diff --git a/arrow-row/src/variable.rs b/arrow-row/src/variable.rs
index 4451c52873..466214e754 100644
--- a/arrow-row/src/variable.rs
+++ b/arrow-row/src/variable.rs
@@ -85,7 +85,7 @@ pub fn encode<'a, I: Iterator<Item = Option<&'a [u8]>>>(
pub fn encode_one(out: &mut [u8], val: Option<&[u8]>, opts: SortOptions) -> usize {
match val {
- Some(val) if val.is_empty() => {
+ Some([]) => {
out[0] = match opts.descending {
true => !EMPTY_SENTINEL,
false => EMPTY_SENTINEL,