Skip to content

Commit

Permalink
fix(rust, python): fix top_k on empty (#5865)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Dec 20, 2022
1 parent 0fd735b commit 3860fb2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions polars/polars-ops/src/chunked_array/top_k.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ where
}

pub fn top_k(s: &Series, k: usize, reverse: bool) -> PolarsResult<Series> {
if s.is_empty() {
return Ok(s.clone());
}
let dtype = s.dtype();

let s = s.to_physical_repr();
Expand Down
6 changes: 6 additions & 0 deletions py-polars/tests/unit/test_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ def test_empty_str_concat_lit() -> None:
"b": pl.Utf8,
"literal": pl.Utf8,
}


def test_top_k_empty() -> None:
df = pl.DataFrame({"test": []})

assert df.select([pl.col("test").top_k(2)]).frame_equal(df)

0 comments on commit 3860fb2

Please sign in to comment.