polars_plan/dsl/
random.rs

1use super::*;
2
3impl Expr {
4    pub fn shuffle(self, seed: Option<u64>) -> Self {
5        self.map_unary(FunctionExpr::Random {
6            method: RandomMethod::Shuffle,
7            seed,
8        })
9    }
10
11    pub fn sample_n(
12        self,
13        n: Expr,
14        with_replacement: bool,
15        shuffle: bool,
16        seed: Option<u64>,
17    ) -> Self {
18        self.map_binary(
19            FunctionExpr::Random {
20                method: RandomMethod::Sample {
21                    is_fraction: false,
22                    with_replacement,
23                    shuffle,
24                },
25                seed,
26            },
27            n,
28        )
29    }
30
31    pub fn sample_frac(
32        self,
33        frac: Expr,
34        with_replacement: bool,
35        shuffle: bool,
36        seed: Option<u64>,
37    ) -> Self {
38        self.map_binary(
39            FunctionExpr::Random {
40                method: RandomMethod::Sample {
41                    is_fraction: true,
42                    with_replacement,
43                    shuffle,
44                },
45                seed,
46            },
47            frac,
48        )
49    }
50}