Skip to content

Commit

Permalink
ensure before cast
Browse files Browse the repository at this point in the history
  • Loading branch information
reswqa committed Sep 25, 2023
1 parent f104cfa commit c9bc01c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/polars-plan/src/dsl/function_expr/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ pub(super) fn sample_n(
let src = &s[0];
let n_s = &s[1];

let n_s = n_s.cast(&IDX_DTYPE)?;
let n = n_s.idx()?;

polars_ensure!(
n.len() == 1,
n_s.len() == 1,
ComputeError: "Sample size must be a single value."
);

let n_s = n_s.cast(&IDX_DTYPE)?;
let n = n_s.idx()?;

match n.get(0) {
Some(n) => src.sample_n(n as usize, with_replacement, shuffle, seed),
None => Ok(Series::new_empty(src.name(), src.dtype())),
Expand Down

0 comments on commit c9bc01c

Please sign in to comment.