Path: blob/main/crates/polars-arrow/src/array/list/proptest.rs
6939 views
use proptest::prelude::{Strategy, any, any_with};1use proptest::sample::SizeRange;23use super::ListArray;4use crate::bitmap::Bitmap;5use crate::datatypes::{ArrowDataType, Field};6use crate::offset::OffsetsBuffer;78pub fn list_array_with_dtype(9size_range: impl Into<SizeRange>,10field: Box<Field>,11) -> impl Strategy<Value = ListArray<i64>> {12let size_range = size_range.into();13(14any::<bool>(),15any_with::<Vec<(bool, u32)>>(size_range.lift()),16)17.prop_flat_map(move |(do_validity, values)| {18let field = field.clone();19let validity = do_validity.then(|| Bitmap::from_iter(values.iter().map(|(v, _)| *v)));2021let mut offsets = Vec::with_capacity(values.len() + 1);22offsets.push(0i64);23for (_, value) in &values {24let value = *value % 7;25offsets.push(*offsets.last().unwrap() + value as i64);26}2728let child_length = *offsets.last().unwrap();29let offsets = unsafe { OffsetsBuffer::new_unchecked(offsets.into()) };3031crate::array::proptest::array_with_dtype(field.dtype.clone(), child_length as usize)32.prop_map(move |child_array| {33ListArray::<i64>::new(34ArrowDataType::LargeList(field.clone()),35offsets.clone(),36child_array,37validity.clone(),38)39})40})41}424344