Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
reswqa committed Sep 24, 2023
1 parent c224cde commit bc7c530
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions crates/polars-core/src/chunked_array/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ impl DataFrame {
shuffle: bool,
seed: Option<u64>,
) -> PolarsResult<Self> {
let n = n.cast(&IDX_DTYPE)?;
let n = n.idx()?;

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

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

match n.get(0) {
Some(n) => self.sample_n_literal(n as usize, with_replacement, shuffle, seed),
None => {
Expand Down
4 changes: 3 additions & 1 deletion py-polars/polars/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -8739,7 +8739,9 @@ def sample(

if n is None:
n = 1
n = _prepare_other_arg(n, 1)

if not isinstance(n, pl.Series):
n = pl.Series("", [n])

return self._from_pydf(self._df.sample_n(n._s, with_replacement, shuffle, seed))

Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8038,7 +8038,7 @@ def shuffle(self, seed: int | None = None) -> Self:

def sample(
self,
n: IntoExpr = None,
n: int | Expr | None = None,
*,
fraction: float | None = None,
with_replacement: bool = False,
Expand Down

0 comments on commit bc7c530

Please sign in to comment.