Path: blob/main/crates/polars-core/src/frame/proptest.rs
7884 views
use std::ops::RangeInclusive;1use std::rc::Rc;23use proptest::prelude::*;45use crate::prelude::{Column, DataFrame};6use crate::series::proptest::{SeriesArbitraryOptions, series_strategy};78pub struct DataFrameArbitraryOptions {9pub series_options: SeriesArbitraryOptions,10pub num_columns: RangeInclusive<usize>,11}1213impl Default for DataFrameArbitraryOptions {14fn default() -> Self {15Self {16series_options: SeriesArbitraryOptions::default(),17num_columns: 0..=5,18}19}20}2122pub fn dataframe_strategy(23options: Rc<DataFrameArbitraryOptions>,24nesting_level: usize,25) -> impl Strategy<Value = DataFrame> {26options27.series_options28.series_length_range29.clone()30.prop_flat_map(move |series_length| {31let mut opts = options.series_options.clone();32opts.series_length_range = series_length..=series_length;3334prop::collection::vec(35series_strategy(Rc::new(opts), nesting_level),36options.num_columns.clone(),37)38})39.prop_map(|series| DataFrame::new(series.into_iter().map(Column::from).collect()).unwrap())40}414243