Skip to content

Commit

Permalink
chore: Update rustc (#21647)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Mar 7, 2025
1 parent 3089206 commit bad9799
Show file tree
Hide file tree
Showing 97 changed files with 298 additions and 307 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ jobs:
}
continue-on-error: true

- name: Run benchmark tests
uses: CodSpeedHQ/action@v3
with:
working-directory: py-polars
run: pytest -m benchmark --codspeed -v
# - name: Run benchmark tests
# uses: CodSpeedHQ/action@v3
# with:
# working-directory: py-polars
# run: pytest -m benchmark --codspeed -v

- name: Run non-benchmark tests
working-directory: py-polars
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-arrow/src/array/binview/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl<T: ViewType + ?Sized> MutableBinaryViewArray<T> {
self.init_validity(false);
}
self.views
.extend(std::iter::repeat(View::default()).take(additional));
.extend(std::iter::repeat_n(View::default(), additional));
if let Some(validity) = &mut self.validity {
validity.extend_constant(additional, false);
}
Expand All @@ -365,7 +365,7 @@ impl<T: ViewType + ?Sized> MutableBinaryViewArray<T> {
})
.unwrap_or_default();
self.views
.extend(std::iter::repeat(view_value).take(additional));
.extend(std::iter::repeat_n(view_value, additional));
}

impl_mutable_array_mut_validity!();
Expand Down
7 changes: 4 additions & 3 deletions crates/polars-arrow/src/array/boolean/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ impl MutableBooleanArray {
if value.is_none() && self.validity.is_none() {
// When the validity is None, all elements so far are valid. When one of the elements is set of null,
// the validity must be initialized.
self.validity = Some(MutableBitmap::from_trusted_len_iter(
std::iter::repeat(true).take(self.len()),
));
self.validity = Some(MutableBitmap::from_trusted_len_iter(std::iter::repeat_n(
true,
self.len(),
)));
}
if let Some(x) = self.validity.as_mut() {
x.set(index, value.is_some())
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/array/fixed_size_list/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<A: ffi::ArrowArrayRef> FromFfi<A> for FixedSizeListArray {
let child = unsafe { array.child(0) }?;
let values = ffi::try_from(child)?;

let length = if values.len() == 0 {
let length = if values.is_empty() {
0
} else {
polars_ensure!(width > 0, InvalidOperation: "Zero-width array with values");
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-arrow/src/array/fixed_size_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl FixedSizeListArray {
values.len() / size,
length,
);
polars_ensure!(size != 0 || values.len() == 0, ComputeError:
polars_ensure!(size != 0 || values.is_empty(), ComputeError:
"zero width FixedSizeListArray has values (length = {}).",
values.len(),
);
Expand All @@ -84,7 +84,7 @@ impl FixedSizeListArray {

#[inline]
fn has_invariants(&self) -> bool {
let has_valid_length = (self.size == 0 && self.values().len() == 0)
let has_valid_length = (self.size == 0 && self.values().is_empty())
|| (self.size > 0
&& self.values().len() % self.size() == 0
&& self.values().len() / self.size() == self.length);
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/array/static_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub trait StaticArray:
fn full_null(length: usize, dtype: ArrowDataType) -> Self;

fn full(length: usize, value: Self::ValueT<'_>, dtype: ArrowDataType) -> Self {
Self::arr_from_iter_with_dtype(dtype, std::iter::repeat(value).take(length))
Self::arr_from_iter_with_dtype(dtype, std::iter::repeat_n(value, length))
}
}

Expand Down
3 changes: 1 addition & 2 deletions crates/polars-arrow/src/bitmap/bitmap_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ where
pub(crate) fn align(bitmap: &Bitmap, new_offset: usize) -> Bitmap {
let length = bitmap.len();

let bitmap: Bitmap = std::iter::repeat(false)
.take(new_offset)
let bitmap: Bitmap = std::iter::repeat_n(false, new_offset)
.chain(bitmap.iter())
.collect();

Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/bitmap/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl Bitmap {
///
/// The returned tuple contains:
/// * `.1`: The byte slice, truncated to the start of the first bit. So the start of the slice
/// is within the first 8 bits.
/// is within the first 8 bits.
/// * `.2`: The start offset in bits on a range `0 <= offsets < 8`.
/// * `.3`: The length in number of bits.
#[inline]
Expand Down
6 changes: 3 additions & 3 deletions crates/polars-arrow/src/bitmap/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl MutableBitmap {
let required = (self.length + additional).saturating_add(7) / 8;
// add remaining as full bytes
self.buffer
.extend(std::iter::repeat(0b11111111u8).take(required - existing));
.extend(std::iter::repeat_n(0b11111111u8, required - existing));
self.length += additional;
}
}
Expand Down Expand Up @@ -555,7 +555,7 @@ unsafe fn extend_aligned_trusted_iter_unchecked(
let chunks = additional_bits / 64;
let remainder = additional_bits % 64;

let additional = (additional_bits + 7) / 8;
let additional = additional_bits.div_ceil(8);
assert_eq!(
additional,
// a hint of how the following calculation will be done
Expand Down Expand Up @@ -687,7 +687,7 @@ impl MutableBitmap {
{
let length = iterator.size_hint().1.unwrap();

let mut buffer = vec![0u8; (length + 7) / 8];
let mut buffer = vec![0u8; length.div_ceil(8)];

let chunks = length / 8;
let reminder = length % 8;
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/bitmap/utils/chunk_iterator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'a, T: BitChunk> BitChunks<'a, T> {
let size_of = size_of::<T>();

let bytes_len = len / 8;
let bytes_upper_len = (len + bit_offset + 7) / 8;
let bytes_upper_len = (len + bit_offset).div_ceil(8);
let mut chunks = slice[..bytes_len].chunks_exact(size_of);

let remainder = &slice[bytes_len - chunks.remainder().len()..bytes_upper_len];
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/bitmap/utils/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn fmt(
return Ok(());
}

let last = bytes[std::cmp::min((length + offset + 7) / 8, bytes.len() - 1)];
let last = bytes[std::cmp::min((length + offset).div_ceil(8), bytes.len() - 1)];
let remaining = (length + offset) % 8;
f.write_str(", ")?;
f.write_str("0b")?;
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/compute/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl DecimalFmtBuffer {
self.len += 1;

let rem_fmt = itoa_buf.format(rem + factor); // + factor adds leading 1 where period would be.
self.data[self.len..self.len + rem_fmt.len() - 1].copy_from_slice(rem_fmt[1..].as_bytes());
self.data[self.len..self.len + rem_fmt.len() - 1].copy_from_slice(&rem_fmt.as_bytes()[1..]);
self.len += rem_fmt.len() - 1;

if trim_zeros {
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/io/ipc/read/read_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ fn read_compressed_bitmap<R: Read + Seek>(
reader: &mut R,
scratch: &mut Vec<u8>,
) -> PolarsResult<Vec<u8>> {
let mut buffer = vec![0; (length + 7) / 8];
let mut buffer = vec![0; length.div_ceil(8)];

scratch.clear();
scratch.try_reserve(bytes)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/legacy/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ pub fn convert_inner_type(array: &dyn Array, dtype: &ArrowDataType) -> Box<dyn A
let length = if width == array.size() {
array.len()
} else {
assert!(array.values().len() > 0 || width != 0);
assert!(!array.values().is_empty() || width != 0);
if width == 0 {
0
} else {
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-arrow/src/legacy/kernels/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ where
if truthy {
av.extend_from_slice(&values[lower..upper])
} else {
av.extend_trusted_len(std::iter::repeat(value).take(upper - lower))
av.extend_trusted_len(std::iter::repeat_n(value, upper - lower))
}
});

Expand All @@ -49,7 +49,7 @@ pub fn set_with_mask<T: NativeType>(
let mut buf = Vec::with_capacity(array.len());
BinaryMaskedSliceIterator::new(mask).for_each(|(lower, upper, truthy)| {
if truthy {
buf.extend_trusted_len(std::iter::repeat(value).take(upper - lower))
buf.extend_trusted_len(std::iter::repeat_n(value, upper - lower))
} else {
buf.extend_from_slice(&values[lower..upper])
}
Expand Down
5 changes: 4 additions & 1 deletion crates/polars-arrow/src/legacy/kernels/sorted_join/left.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ pub fn join<T: PartialOrd + Copy + Debug>(

let first_right = right[right_idx as usize];
let mut left_idx = left.partition_point(|v| v < &first_right) as IdxSize;
out_rhs.extend(std::iter::repeat(NullableIdxSize::null()).take(left_idx as usize));
out_rhs.extend(std::iter::repeat_n(
NullableIdxSize::null(),
left_idx as usize,
));
out_lhs.extend(left_offset..(left_idx + left_offset));

for &val_l in &left[left_idx as usize..] {
Expand Down
6 changes: 4 additions & 2 deletions crates/polars-arrow/src/trusted_len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ unsafe impl<A: Clone> TrustedLen for std::iter::Repeat<A> {}
unsafe impl<A, F: FnMut() -> A> TrustedLen for std::iter::RepeatWith<F> {}
unsafe impl<A: TrustedLen> TrustedLen for std::iter::Take<A> {}

unsafe impl<A: Clone> TrustedLen for std::iter::RepeatN<A> {}

unsafe impl<T> TrustedLen for &mut dyn TrustedLen<Item = T> {}
unsafe impl<T> TrustedLen for Box<dyn TrustedLen<Item = T> + '_> {}

Expand Down Expand Up @@ -100,11 +102,11 @@ where
}
}

impl<J: Clone> TrustMyLength<std::iter::Take<std::iter::Repeat<J>>, J> {
impl<J: Clone> TrustMyLength<std::iter::RepeatN<J>, J> {
/// Create a new `TrustMyLength` iterator that repeats `value` `len` times.
pub fn new_repeat_n(value: J, len: usize) -> Self {
// SAFETY: This is always safe since repeat(..).take(n) always repeats exactly `n` times`.
unsafe { Self::new(std::iter::repeat(value).take(len), len) }
unsafe { Self::new(std::iter::repeat_n(value, len), len) }
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/polars-compute/src/rolling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn det_offsets(i: Idx, window_size: WindowSize, _len: Len) -> (usize, usize) {
(i.saturating_sub(window_size - 1), i + 1)
}
fn det_offsets_center(i: Idx, window_size: WindowSize, len: Len) -> (usize, usize) {
let right_window = (window_size + 1) / 2;
let right_window = window_size.div_ceil(2);
(
i.saturating_sub(window_size - right_window),
std::cmp::min(len, i + right_window),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;

#[allow(clippy::large_enum_variant)]
pub(super) enum DtypeMerger {
#[cfg(feature = "dtype-categorical")]
Categorical(GlobalRevMapMerger, CategoricalOrdering),
Expand Down
1 change: 1 addition & 0 deletions crates/polars-core/src/chunked_array/comparison/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,7 @@ impl ChunkEqualElement for ListChunked {}
impl ChunkEqualElement for ArrayChunked {}

#[cfg(test)]
#[cfg_attr(feature = "nightly", allow(clippy::manual_repeat_n))] // remove once stable
mod test {
use std::iter::repeat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub(crate) fn create_extension<I: Iterator<Item = Option<T>> + TrustedLen, T: Si
// when we transmute from &[u8] to T, T must be aligned correctly,
// so we pad with bytes until the alignment matches
let n_padding = (buf.as_ptr() as usize) % t_alignment;
buf.extend(std::iter::repeat(0).take(n_padding));
buf.extend(std::iter::repeat_n(0, n_padding));

// transmute T as bytes and copy in buffer
for opt_t in iter.into_iter() {
Expand Down
1 change: 1 addition & 0 deletions crates/polars-core/src/chunked_array/ops/aggregate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ mod test {
use crate::prelude::*;

#[test]
#[cfg(not(miri))]
fn test_var() {
// Validated with numpy. Note that numpy uses ddof as an argument which
// influences results. The default ddof=0, we chose ddof=1, which is
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-core/src/chunked_array/ops/append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub(crate) fn new_chunks(chunks: &mut Vec<ArrayRef>, other: &[ArrayRef], len: us
other.clone_into(chunks);
} else {
for chunk in other {
if chunk.len() > 0 {
if !chunk.is_empty() {
chunks.push(chunk.clone());
}
}
Expand All @@ -22,7 +22,7 @@ pub(crate) fn new_chunks_owned(chunks: &mut Vec<ArrayRef>, other: Vec<ArrayRef>,
*chunks = other;
} else {
chunks.reserve(other.len());
chunks.extend(other.into_iter().filter(|c| c.len() > 0));
chunks.extend(other.into_iter().filter(|c| !c.is_empty()));
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/polars-core/src/chunked_array/ops/chunkops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl<T: PolarsDataType> ChunkedArray<T> {
true
} else {
// Remove the empty chunks
arr.len() > 0
!arr.is_empty()
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-core/src/chunked_array/ops/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl ChunkFullNull for BinaryChunked {
impl<'a> ChunkFull<&'a [u8]> for BinaryOffsetChunked {
fn full(name: PlSmallStr, value: &'a [u8], length: usize) -> Self {
let mut mutable = MutableBinaryArray::with_capacities(length, length * value.len());
mutable.extend_values(std::iter::repeat(value).take(length));
mutable.extend_values(std::iter::repeat_n(value, length));
let arr: BinaryArray<i64> = mutable.into();
let mut out = ChunkedArray::with_chunk(name, arr);
out.set_sorted_flag(IsSorted::Ascending);
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-core/src/chunked_array/ops/rolling_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mod inner_mod {
/// utility
fn window_edges(idx: usize, len: usize, window_size: usize, center: bool) -> (usize, usize) {
let (start, end) = if center {
let right_window = (window_size + 1) / 2;
let right_window = window_size.div_ceil(2);
(
idx.saturating_sub(window_size - right_window),
len.min(idx + right_window),
Expand Down Expand Up @@ -231,7 +231,7 @@ mod inner_mod {
let validity_slice = validity.as_mut_slice();

let mut values = Vec::with_capacity(ca.len());
values.extend(std::iter::repeat(T::Native::default()).take(window_size - 1));
values.extend(std::iter::repeat_n(T::Native::default(), window_size - 1));

for offset in 0..self.len() + 1 - window_size {
debug_assert!(offset + window_size <= arr.len());
Expand Down
8 changes: 4 additions & 4 deletions crates/polars-core/src/chunked_array/ops/sort/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ where
let mut vals = Vec::with_capacity(ca.len());

if !options.nulls_last {
let iter = std::iter::repeat(T::Native::default()).take(null_count);
let iter = std::iter::repeat_n(T::Native::default(), null_count);
vals.extend(iter);
}

Expand All @@ -225,7 +225,7 @@ where
sort_impl_unstable(mut_slice, options);

if options.nulls_last {
vals.extend(std::iter::repeat(T::Native::default()).take(ca.null_count()));
vals.extend(std::iter::repeat_n(T::Native::default(), ca.null_count()));
}

let arr = PrimitiveArray::new(
Expand Down Expand Up @@ -534,7 +534,7 @@ impl ChunkSort<BinaryOffsetType> for BinaryOffsetChunked {
length_so_far = values.len() as i64;
offsets.push(length_so_far);
}
offsets.extend(std::iter::repeat(length_so_far).take(null_count));
offsets.extend(std::iter::repeat_n(length_so_far, null_count));

// SAFETY: offsets are correctly created.
let arr = unsafe {
Expand All @@ -547,7 +547,7 @@ impl ChunkSort<BinaryOffsetType> for BinaryOffsetChunked {
ChunkedArray::with_chunk(self.name().clone(), arr)
},
(_, false) => {
offsets.extend(std::iter::repeat(length_so_far).take(null_count));
offsets.extend(std::iter::repeat_n(length_so_far, null_count));

for val in v {
values.extend_from_slice(val);
Expand Down
7 changes: 3 additions & 4 deletions crates/polars-core/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ impl Display for DataFrame {
let padding = 2; // eg: one char either side of the value

let (n_first, n_last) = if self.width() > max_n_cols {
((max_n_cols + 1) / 2, max_n_cols / 2)
(max_n_cols.div_ceil(2), max_n_cols / 2)
} else {
(self.width(), 0)
};
Expand Down Expand Up @@ -839,15 +839,14 @@ fn fmt_int_string_custom(num: &str, group_size: u8, group_separator: &str) -> St
} else {
0
};
let int_body = num[sign_offset..]
.as_bytes()
let int_body = &num.as_bytes()[sign_offset..]
.rchunks(group_size as usize)
.rev()
.map(str::from_utf8)
.collect::<Result<Vec<&str>, _>>()
.unwrap()
.join(group_separator);
out.push_str(&int_body);
out.push_str(int_body);
out
}
}
Expand Down
Loading

0 comments on commit bad9799

Please sign in to comment.