Skip to content

Commit

Permalink
Update rand requirement from 0.8 to 0.9 (#7045)
Browse files Browse the repository at this point in the history
* Update rand requirement from 0.8 to 0.9

Updates the requirements on [rand](https://github.com/rust-random/rand) to permit the latest version.
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [Commits](rust-random/rand@0.8.0...0.9.0)

---
updated-dependencies:
- dependency-name: rand
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* Migrate to 0.9

* Add missing feature, also bump `rand` in `object_store`

* Rustfmt

* Name `UniformUsize` instance  `uusize` instead of `usize`

* Rename another use of `usize`

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
mbrobbel and dependabot[bot] authored Feb 2, 2025
1 parent fdbef3f commit 69eeee3
Show file tree
Hide file tree
Showing 73 changed files with 423 additions and 389 deletions.
2 changes: 1 addition & 1 deletion arrow-array/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ffi = ["arrow-schema/ffi", "arrow-data/ffi"]
force_validate = []

[dev-dependencies]
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"] }
rand = { version = "0.9", default-features = false, features = ["std", "std_rng", "thread_rng"] }
criterion = { version = "0.5", default-features = false }

[build-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions arrow-array/benches/fixed_size_list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
use arrow_array::{Array, FixedSizeListArray, Int32Array};
use arrow_schema::Field;
use criterion::*;
use rand::{thread_rng, Rng};
use rand::{rng, Rng};
use std::sync::Arc;

fn gen_fsl(len: usize, value_len: usize) -> FixedSizeListArray {
let mut rng = thread_rng();
let mut rng = rng();
let values = Arc::new(Int32Array::from(
(0..len).map(|_| rng.gen::<i32>()).collect::<Vec<_>>(),
(0..len).map(|_| rng.random::<i32>()).collect::<Vec<_>>(),
));
let field = Arc::new(Field::new_list_field(values.data_type().clone(), true));
FixedSizeListArray::new(field, value_len as i32, values, None)
Expand Down
8 changes: 4 additions & 4 deletions arrow-array/benches/occupancy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use arrow_array::types::Int32Type;
use arrow_array::{DictionaryArray, Int32Array};
use arrow_buffer::NullBuffer;
use criterion::*;
use rand::{thread_rng, Rng};
use rand::{rng, Rng};
use std::sync::Arc;

fn gen_dict(
Expand All @@ -28,11 +28,11 @@ fn gen_dict(
occupancy: f64,
null_percent: f64,
) -> DictionaryArray<Int32Type> {
let mut rng = thread_rng();
let mut rng = rng();
let values = Int32Array::from(vec![0; values_len]);
let max_key = (values_len as f64 * occupancy) as i32;
let keys = (0..len).map(|_| rng.gen_range(0..max_key)).collect();
let nulls = (0..len).map(|_| !rng.gen_bool(null_percent)).collect();
let keys = (0..len).map(|_| rng.random_range(0..max_key)).collect();
let nulls = (0..len).map(|_| !rng.random_bool(null_percent)).collect();

let keys = Int32Array::new(keys, Some(NullBuffer::new(nulls)));
DictionaryArray::new(keys, Arc::new(values))
Expand Down
12 changes: 6 additions & 6 deletions arrow-array/benches/union_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ use arrow_array::{Array, ArrayRef, Int32Array, UnionArray};
use arrow_buffer::{NullBuffer, ScalarBuffer};
use arrow_schema::{DataType, Field, UnionFields};
use criterion::*;
use rand::{thread_rng, Rng};
use rand::{rng, Rng};

fn array_with_nulls() -> ArrayRef {
let mut rng = thread_rng();
let mut rng = rng();

let values = ScalarBuffer::from_iter(repeat_with(|| rng.gen()).take(4096));
let values = ScalarBuffer::from_iter(repeat_with(|| rng.random()).take(4096));

// nulls with at least one null and one valid
let nulls: NullBuffer = [true, false]
.into_iter()
.chain(repeat_with(|| rng.gen()))
.chain(repeat_with(|| rng.random()))
.take(4096)
.collect();

Arc::new(Int32Array::new(values.clone(), Some(nulls)))
}

fn array_without_nulls() -> ArrayRef {
let mut rng = thread_rng();
let mut rng = rng();

let values = ScalarBuffer::from_iter(repeat_with(|| rng.gen()).take(4096));
let values = ScalarBuffer::from_iter(repeat_with(|| rng.random()).take(4096));

Arc::new(Int32Array::new(values.clone(), None))
}
Expand Down
8 changes: 4 additions & 4 deletions arrow-array/src/array/boolean_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ impl From<BooleanBuffer> for BooleanArray {
mod tests {
use super::*;
use arrow_buffer::Buffer;
use rand::{thread_rng, Rng};
use rand::{rng, Rng};

#[test]
fn test_boolean_fmt_debug() {
Expand Down Expand Up @@ -667,11 +667,11 @@ mod tests {
#[test]
#[cfg_attr(miri, ignore)] // Takes too long
fn test_true_false_count() {
let mut rng = thread_rng();
let mut rng = rng();

for _ in 0..10 {
// No nulls
let d: Vec<_> = (0..2000).map(|_| rng.gen_bool(0.5)).collect();
let d: Vec<_> = (0..2000).map(|_| rng.random_bool(0.5)).collect();
let b = BooleanArray::from(d.clone());

let expected_true = d.iter().filter(|x| **x).count();
Expand All @@ -680,7 +680,7 @@ mod tests {

// With nulls
let d: Vec<_> = (0..2000)
.map(|_| rng.gen_bool(0.5).then(|| rng.gen_bool(0.5)))
.map(|_| rng.random_bool(0.5).then(|| rng.random_bool(0.5)))
.collect();
let b = BooleanArray::from(d.clone());

Expand Down
10 changes: 5 additions & 5 deletions arrow-array/src/array/run_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,8 @@ where

#[cfg(test)]
mod tests {
use rand::rng;
use rand::seq::SliceRandom;
use rand::thread_rng;
use rand::Rng;

use super::*;
Expand Down Expand Up @@ -691,7 +691,7 @@ mod tests {
];
let mut result: Vec<Option<i32>> = Vec::with_capacity(size);
let mut ix = 0;
let mut rng = thread_rng();
let mut rng = rng();
// run length can go up to 8. Cap the max run length for smaller arrays to size / 2.
let max_run_length = 8_usize.min(1_usize.max(size / 2));
while result.len() < size {
Expand All @@ -700,7 +700,7 @@ mod tests {
seed.shuffle(&mut rng);
}
// repeat the items between 1 and 8 times. Cap the length for smaller sized arrays
let num = max_run_length.min(rand::thread_rng().gen_range(1..=max_run_length));
let num = max_run_length.min(rand::rng().random_range(1..=max_run_length));
for _ in 0..num {
result.push(seed[ix]);
}
Expand Down Expand Up @@ -1000,7 +1000,7 @@ mod tests {
let mut logical_indices: Vec<u32> = (0_u32..(logical_len as u32)).collect();
// add same indices once more
logical_indices.append(&mut logical_indices.clone());
let mut rng = thread_rng();
let mut rng = rng();
logical_indices.shuffle(&mut rng);

let physical_indices = run_array.get_physical_indices(&logical_indices).unwrap();
Expand Down Expand Up @@ -1036,7 +1036,7 @@ mod tests {
let mut logical_indices: Vec<u32> = (0_u32..(slice_len as u32)).collect();
// add same indices once more
logical_indices.append(&mut logical_indices.clone());
let mut rng = thread_rng();
let mut rng = rng();
logical_indices.shuffle(&mut rng);

// test for offset = 0 and slice length = slice_len
Expand Down
6 changes: 3 additions & 3 deletions arrow-array/src/run_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ where

#[cfg(test)]
mod tests {
use rand::{seq::SliceRandom, thread_rng, Rng};
use rand::{rng, seq::SliceRandom, Rng};

use crate::{
array::{Int32Array, StringArray},
Expand Down Expand Up @@ -200,7 +200,7 @@ mod tests {
];
let mut result: Vec<Option<i32>> = Vec::with_capacity(size);
let mut ix = 0;
let mut rng = thread_rng();
let mut rng = rng();
// run length can go up to 8. Cap the max run length for smaller arrays to size / 2.
let max_run_length = 8_usize.min(1_usize.max(size / 2));
while result.len() < size {
Expand All @@ -209,7 +209,7 @@ mod tests {
seed.shuffle(&mut rng);
}
// repeat the items between 1 and 8 times. Cap the length for smaller sized arrays
let num = max_run_length.min(rand::thread_rng().gen_range(1..=max_run_length));
let num = max_run_length.min(rand::rng().random_range(1..=max_run_length));
for _ in 0..num {
result.push(seed[ix]);
}
Expand Down
3 changes: 1 addition & 2 deletions arrow-avro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ crc = { version = "3.0", optional = true }


[dev-dependencies]
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"] }

rand = { version = "0.9", default-features = false, features = ["std", "std_rng", "thread_rng"] }
2 changes: 1 addition & 1 deletion arrow-buffer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ half = { version = "2.1", default-features = false }

[dev-dependencies]
criterion = { version = "0.5", default-features = false }
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"] }
rand = { version = "0.9", default-features = false, features = ["std", "std_rng", "thread_rng"] }

[build-dependencies]

Expand Down
8 changes: 4 additions & 4 deletions arrow-buffer/benches/i256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ fn criterion_benchmark(c: &mut Criterion) {

let numerators: Vec<_> = (0..SIZE)
.map(|_| {
let high = rng.gen_range(1000..i128::MAX);
let low = rng.gen();
let high = rng.random_range(1000..i128::MAX);
let low = rng.random();
i256::from_parts(low, high)
})
.collect();

let divisors: Vec<_> = numerators
.iter()
.map(|n| {
let quotient = rng.gen_range(1..100_i32);
let quotient = rng.random_range(1..100_i32);
n.wrapping_div(i256::from(quotient))
})
.collect();
Expand All @@ -70,7 +70,7 @@ fn criterion_benchmark(c: &mut Criterion) {
});

let divisors: Vec<_> = (0..SIZE)
.map(|_| i256::from(rng.gen_range(1..100_i32)))
.map(|_| i256::from(rng.random_range(1..100_i32)))
.collect();

c.bench_function("i256_div_rem small divisor", |b| {
Expand Down
2 changes: 1 addition & 1 deletion arrow-buffer/benches/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const SIZE: usize = 1024;

fn criterion_benchmark(c: &mut Criterion) {
let mut rng = StdRng::seed_from_u64(42);
let lengths: Vec<usize> = black_box((0..SIZE).map(|_| rng.gen_range(0..40)).collect());
let lengths: Vec<usize> = black_box((0..SIZE).map(|_| rng.random_range(0..40)).collect());

c.bench_function("OffsetBuffer::from_lengths", |b| {
b.iter(|| OffsetBuffer::<i32>::from_lengths(lengths.iter().copied()));
Expand Down
12 changes: 6 additions & 6 deletions arrow-buffer/src/bigint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ impl ToPrimitive for i256 {
mod tests {
use super::*;
use num::Signed;
use rand::{thread_rng, Rng};
use rand::{rng, Rng};

#[test]
fn test_signed_cmp() {
Expand Down Expand Up @@ -1091,16 +1091,16 @@ mod tests {
#[test]
#[cfg_attr(miri, ignore)]
fn test_i256_fuzz() {
let mut rng = thread_rng();
let mut rng = rng();

for _ in 0..1000 {
let mut l = [0_u8; 32];
let len = rng.gen_range(0..32);
l.iter_mut().take(len).for_each(|x| *x = rng.gen());
let len = rng.random_range(0..32);
l.iter_mut().take(len).for_each(|x| *x = rng.random());

let mut r = [0_u8; 32];
let len = rng.gen_range(0..32);
r.iter_mut().take(len).for_each(|x| *x = rng.gen());
let len = rng.random_range(0..32);
r.iter_mut().take(len).for_each(|x| *x = rng.random());

test_ops(i256::from_le_bytes(l), i256::from_le_bytes(r))
}
Expand Down
2 changes: 1 addition & 1 deletion arrow-buffer/src/builder/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ mod tests {

let mut buffer = BooleanBufferBuilder::new(12);
let mut all_bools = vec![];
let mut rng = rand::thread_rng();
let mut rng = rand::rng();

let src_len = 32;
let (src, compacted_src) = {
Expand Down
17 changes: 12 additions & 5 deletions arrow-buffer/src/util/bit_chunk_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,10 @@ impl ExactSizeIterator for BitChunkIterator<'_> {

#[cfg(test)]
mod tests {
use rand::distr::uniform::UniformSampler;
use rand::distr::uniform::UniformUsize;
use rand::prelude::*;
use rand::rng;

use crate::buffer::Buffer;
use crate::util::bit_chunk_iterator::UnalignedBitChunk;
Expand Down Expand Up @@ -624,21 +627,25 @@ mod tests {
#[test]
#[cfg_attr(miri, ignore)]
fn fuzz_unaligned_bit_chunk_iterator() {
let mut rng = thread_rng();
let mut rng = rng();

let uusize = UniformUsize::new(usize::MIN, usize::MAX).unwrap();
for _ in 0..100 {
let mask_len = rng.gen_range(0..1024);
let bools: Vec<_> = std::iter::from_fn(|| Some(rng.gen()))
let mask_len = rng.random_range(0..1024);
let bools: Vec<_> = std::iter::from_fn(|| Some(rng.random()))
.take(mask_len)
.collect();

let buffer = Buffer::from_iter(bools.iter().cloned());

let max_offset = 64.min(mask_len);
let offset = rng.gen::<usize>().checked_rem(max_offset).unwrap_or(0);
let offset = uusize.sample(&mut rng).checked_rem(max_offset).unwrap_or(0);

let max_truncate = 128.min(mask_len - offset);
let truncate = rng.gen::<usize>().checked_rem(max_truncate).unwrap_or(0);
let truncate = uusize
.sample(&mut rng)
.checked_rem(max_truncate)
.unwrap_or(0);

let unaligned =
UnalignedBitChunk::new(buffer.as_slice(), offset, mask_len - offset - truncate);
Expand Down
14 changes: 7 additions & 7 deletions arrow-buffer/src/util/bit_mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ mod tests {
use super::*;
use crate::bit_util::{get_bit, set_bit, unset_bit};
use rand::prelude::StdRng;
use rand::{Fill, Rng, SeedableRng};
use rand::{Rng, SeedableRng, TryRngCore};
use std::fmt::Display;

#[test]
Expand Down Expand Up @@ -322,20 +322,20 @@ mod tests {
// -------------------+-----------------+-------

// length of data to copy
let len = rng.gen_range(0..=200);
let len = rng.random_range(0..=200);

// randomly pick where we will write to
let offset_write_bits = rng.gen_range(0..=200);
let offset_write_bits = rng.random_range(0..=200);
let offset_write_bytes = if offset_write_bits % 8 == 0 {
offset_write_bits / 8
} else {
(offset_write_bits / 8) + 1
};
let extra_write_data_bytes = rng.gen_range(0..=5); // ensure 0 shows up often
let extra_write_data_bytes = rng.random_range(0..=5); // ensure 0 shows up often

// randomly decide where we will read from
let extra_read_data_bytes = rng.gen_range(0..=5); // make sure 0 shows up often
let offset_read_bits = rng.gen_range(0..=200);
let extra_read_data_bytes = rng.random_range(0..=5); // make sure 0 shows up often
let offset_read_bits = rng.random_range(0..=200);
let offset_read_bytes = if offset_read_bits % 8 != 0 {
(offset_read_bits / 8) + 1
} else {
Expand All @@ -356,7 +356,7 @@ mod tests {
self.data
.resize(offset_read_bytes + len + extra_read_data_bytes, 0);
// fill source data with random bytes
self.data.try_fill(rng).unwrap();
rng.try_fill_bytes(self.data.as_mut_slice()).unwrap();
self.offset_read = offset_read_bits;

self.len = len;
Expand Down
Loading

0 comments on commit 69eeee3

Please sign in to comment.