Skip to content

Commit

Permalink
unset sorted on take (#3756)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jun 21, 2022
1 parent a731ec4 commit 4ab6538
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions polars/tests/it/core/random.rs
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());
}

0 comments on commit 4ab6538

Please sign in to comment.