-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use polars_core::series::IsSorted; | ||
use super::*; | ||
|
||
#[test] | ||
fn test_sample_sorted() { | ||
let s = Series::new("a", [1, 2, 3]).sort(false); | ||
matches!(s.is_sorted(),IsSorted::Ascending); | ||
let out = s.sample_frac(1.5, true, false, None).unwrap(); | ||
matches!(s.is_sorted(),IsSorted::Not); | ||
} | ||
|
||
#[test] | ||
fn test_sample() { | ||
let df = df![ | ||
"foo" => &[1, 2, 3, 4, 5] | ||
] | ||
.unwrap(); | ||
|
||
// default samples are random and don't require seeds | ||
assert!(df.sample_n(3, false, false, None).is_ok()); | ||
assert!(df.sample_frac(0.4, false, false, None).is_ok()); | ||
// with seeding | ||
assert!(df.sample_n(3, false, false, Some(0)).is_ok()); | ||
assert!(df.sample_frac(0.4, false, false, Some(0)).is_ok()); | ||
// without replacement can not sample more than 100% | ||
assert!(df.sample_frac(2.0, false, false, Some(0)).is_err()); | ||
assert!(df.sample_n(3, true, false, Some(0)).is_ok()); | ||
assert!(df.sample_frac(0.4, true, false, Some(0)).is_ok()); | ||
// with replacement can sample more than 100% | ||
assert!(df.sample_frac(2.0, true, false, Some(0)).is_ok()); | ||
} |