Skip to content

Commit

Permalink
refactor(rust): match_block_trailing_comma (pola-rs#10414)
Browse files Browse the repository at this point in the history
  • Loading branch information
orlp authored Aug 11, 2023
1 parent 2b91906 commit 5249cb1
Show file tree
Hide file tree
Showing 352 changed files with 2,747 additions and 2,746 deletions.
8 changes: 4 additions & 4 deletions crates/polars-arrow/src/array/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ impl<'a> AnonymousBuilder<'a> {
None => {
let values = NullArray::new(DataType::Null, len).boxed();
(DataType::Null, values)
}
},
Some(inner_dtype) => {
let values = new_null_array(inner_dtype.clone(), len);
(inner_dtype.clone(), values)
}
},
}
} else {
let inner_dtype = inner_dtype.unwrap_or_else(|| self.arrays[0].data_type());
Expand Down Expand Up @@ -187,7 +187,7 @@ pub fn convert_inner_type(array: &dyn Array, dtype: &DataType) -> Box<dyn Array>
array.validity().cloned(),
)
.boxed()
}
},
DataType::Struct(fields) => {
let array = array.as_any().downcast_ref::<StructArray>().unwrap();
let inner = array.values();
Expand All @@ -197,7 +197,7 @@ pub fn convert_inner_type(array: &dyn Array, dtype: &DataType) -> Box<dyn Array>
.map(|(arr, field)| convert_inner_type(arr.as_ref(), field.data_type()))
.collect::<Vec<_>>();
StructArray::new(dtype.clone(), new_values, array.validity().cloned()).boxed()
}
},
_ => new_null_array(dtype.clone(), array.len()),
}
}
12 changes: 6 additions & 6 deletions crates/polars-arrow/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ macro_rules! iter_to_values {
$validity.push(true);
$offsets.push($length_so_far);
Some(it)
}
},
None => {
$validity.push(false);
None
}
},
})
.flatten()
.collect()
Expand Down Expand Up @@ -191,11 +191,11 @@ pub trait ListFromIter {
validity.push(true);
offsets.push(length_so_far);
Some(it)
}
},
None => {
validity.push(false);
None
}
},
})
.flatten()
.trust_my_length(n_elements)
Expand Down Expand Up @@ -237,11 +237,11 @@ pub trait ListFromIter {
validity.push(true);
offsets.push(length_so_far);
Some(it)
}
},
None => {
validity.push(false);
None
}
},
})
.flatten()
.trust_my_length(n_elements)
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn cast(array: &dyn Array, to_type: &DataType) -> Result<Box<dyn Array>> {
DataType::Decimal(precision, scale) if matches!(array.data_type(), DataType::LargeUtf8) => {
let array = array.as_any().downcast_ref::<LargeStringArray>().unwrap();
Ok(cast_utf8_to_decimal(array, Some(*precision), *scale))
}
},
_ => arrow::compute::cast::cast(array, to_type, Default::default()),
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-arrow/src/compute/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ pub(super) fn deserialize_decimal(bytes: &[u8], precision: Option<u8>, scale: u8
return None;
}
atoi::<i128>(rhs)
}
},
(Some(lhs), None) => {
if lhs.len() > precision as usize || scale != 0 {
return None;
}
atoi::<i128>(lhs)
}
},
(None, None) => None,
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-arrow/src/compute/take/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ unsafe fn take_values_indices_validity(
debug_assert!(index < values.len());
validity.push(values_validity.get_bit_unchecked(index));
values_values.get_bit_unchecked(index)
}
},
None => {
validity.push(false);
false
}
},
});
let values = Bitmap::from_trusted_len_iter(values);
(values, validity.into())
Expand Down
10 changes: 5 additions & 5 deletions crates/polars-arrow/src/compute/take/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@ pub unsafe fn take_unchecked(arr: &dyn Array, idx: &IdxArr) -> ArrayRef {
LargeUtf8 => {
let arr = arr.as_any().downcast_ref().unwrap();
take_utf8_unchecked(arr, idx)
}
},
Boolean => {
let arr = arr.as_any().downcast_ref().unwrap();
Box::new(boolean::take_unchecked(arr, idx))
}
},
#[cfg(feature = "dtype-array")]
FixedSizeList => {
let arr = arr.as_any().downcast_ref().unwrap();
Box::new(fixed_size_list::take_unchecked(arr, idx))
}
},
// TODO! implement proper unchecked version
#[cfg(feature = "compute")]
_ => {
use arrow::compute::take::take;
take(arr, idx).unwrap()
}
},
#[cfg(not(feature = "compute"))]
_ => {
panic!("activate compute feature")
}
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/kernels/ewm/average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ where
old_wt = if adjust { old_wt + new_wt } else { T::one() };
}
}
}
},
}
match non_null_cnt < min_periods {
true => None,
Expand Down
8 changes: 4 additions & 4 deletions crates/polars-arrow/src/kernels/ewm/variance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ where
opt_mean_x = opt_x;
opt_mean_y = opt_y;
}
}
},
(_, Some(mean_x), Some(mean_y)) => {
if is_observation || !ignore_nulls {
sum_wt *= old_wt_factor;
Expand Down Expand Up @@ -92,13 +92,13 @@ where
}
}
}
}
},
_ => {
if is_observation {
opt_mean_x = opt_x;
opt_mean_y = opt_y;
}
}
},
}
match (non_na_cnt >= min_periods_fixed, bias) {
(false, _) => None,
Expand All @@ -114,7 +114,7 @@ where
None
}
}
}
},
(true, true) => Some(cov),
}
});
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/kernels/list_bytes_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ unsafe fn bytes_iter<'a, T: NativeType>(
} else {
None
}
}
},
}
})
}
Expand Down
22 changes: 11 additions & 11 deletions crates/polars-arrow/src/kernels/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,21 @@ impl<'a> Iterator for MaskedSlicesIterator<'a> {
// iterating over chunks does not yield any new slice => continue to the next
self.current_bit = 0;
self.next()
}
},
other => other,
}
}
},
State::Bits(mask) => {
match self.iterate_bits(mask, 64) {
None => {
// iterating over bits does not yield any new slice => change back
// to chunks and continue to the next
self.state = State::Chunks;
self.next()
}
},
other => other,
}
}
},
State::Remainder => match self.iterate_bits(self.remainder_mask, self.remainder_len) {
None => {
self.state = State::Finish;
Expand All @@ -175,7 +175,7 @@ impl<'a> Iterator for MaskedSlicesIterator<'a> {
} else {
None
}
}
},
other => other,
},
State::Finish => None,
Expand Down Expand Up @@ -236,23 +236,23 @@ impl<'a> Iterator for BinaryMaskedSliceIterator<'a> {
self.filled = high;
Some((low, high, true))
}
}
},
None => {
self.state = Finish;
Some((self.filled, self.slice_iter.total_len, false))
}
},
}
} else {
self.filled = self.high;
self.state = LastTrue;
Some((self.low, self.high, true))
}
}
},
LastFalse => {
self.state = LastTrue;
self.filled = self.high;
Some((self.low, self.high, true))
}
},
LastTrue => match self.slice_iter.next() {
Some((low, high)) => {
self.low = low;
Expand All @@ -261,15 +261,15 @@ impl<'a> Iterator for BinaryMaskedSliceIterator<'a> {
let last_filled = self.filled;
self.filled = low;
Some((last_filled, low, false))
}
},
None => {
self.state = Finish;
if self.filled != self.slice_iter.total_len {
Some((self.filled, self.slice_iter.total_len, false))
} else {
None
}
}
},
},
Finish => None,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/kernels/rolling/no_nulls/mean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ where
no_nulls::compute_sum_weights,
&wts,
)
}
},
}
}
4 changes: 2 additions & 2 deletions crates/polars-arrow/src/kernels/rolling/no_nulls/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ macro_rules! minmax_window {
} else {
self.update_m_and_m_idx(pm);
}
}
},
(Some(pm), None) => self.update_m_and_m_idx(pm),
(None, Some(em)) => self.update_m_and_m_idx(em),
// This would mean both the entering and previous windows are empty
Expand Down Expand Up @@ -275,7 +275,7 @@ macro_rules! rolling_minmax_func {
$wtd_f,
&weights,
)
}
},
}
}
};
Expand Down
14 changes: 7 additions & 7 deletions crates/polars-arrow/src/kernels/rolling/no_nulls/quantile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<
| QuantileInterpolOptions::Midpoint
| QuantileInterpolOptions::Linear => {
((length as f64 - 1.0) * self.prob).floor() as usize
}
},
QuantileInterpolOptions::Higher => ((length as f64 - 1.0) * self.prob).ceil() as usize,
};

Expand All @@ -69,7 +69,7 @@ impl<

(mid + mid_plus_1) / T::from::<f64>(2.0f64).unwrap()
}
}
},
QuantileInterpolOptions::Linear => {
let float_idx = (length as f64 - 1.0) * self.prob;
let top_idx = f64::ceil(float_idx) as usize;
Expand All @@ -82,12 +82,12 @@ impl<
let proportion = T::from(float_idx - idx as f64).unwrap();
proportion * (vals[top_idx] - vals[idx]) + vals[idx]
}
}
},
_ => {
// safety
// we are in bounds
unsafe { *vals.get_unchecked(idx) }
}
},
}
}
}
Expand Down Expand Up @@ -144,7 +144,7 @@ where
weights,
wsum,
))
}
},
}
}

Expand Down Expand Up @@ -186,12 +186,12 @@ where
} else {
vk
}
}
},
(_, Midpoint) => (vk + v_old) * NumCast::from(0.5).unwrap(),
// This is seemingly the canonical way to do it.
(_, Linear) => {
v_old + <T as NumCast>::from((h - s_old) / (s - s_old)).unwrap() * (vk - v_old)
}
},
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/polars-arrow/src/kernels/rolling/no_nulls/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ where
no_nulls::compute_sum_weights,
&weights,
)
}
},
(false, Some(weights)) => {
let weights = no_nulls::coerce_weights(weights);
no_nulls::rolling_apply_weights(
Expand All @@ -114,7 +114,7 @@ where
no_nulls::compute_sum_weights,
&weights,
)
}
},
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ where
compute_var_weights,
&wts,
)
}
},
}
}

Expand Down
Loading

0 comments on commit 5249cb1

Please sign in to comment.