Skip to content

Commit

Permalink
Fix latest clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold committed Feb 8, 2024
1 parent bd19a62 commit 042bcfd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
11 changes: 5 additions & 6 deletions arrow-arith/src/arity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
81 changes: 41 additions & 40 deletions arrow-array/src/array/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)))
}

Expand All @@ -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)))
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand All @@ -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();

Expand Down Expand Up @@ -847,22 +847,23 @@ 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();
let mut builder = self.into_builder()?;

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()))
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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
///
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1329,17 +1330,17 @@ 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)
}

/// 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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion arrow-row/src/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 042bcfd

Please sign in to comment.