Skip to content

Commit

Permalink
fix: Empty unique (#16214)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored May 14, 2024
1 parent e3c338a commit 993cc99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 9 additions & 3 deletions crates/polars-lazy/src/physical_plan/executors/unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ impl Executor for UniqueExec {
let keep = self.options.keep_strategy;

state.record(
|| match self.options.maintain_order {
true => df.unique_stable(subset, keep, self.options.slice),
false => df.unique(subset, keep, self.options.slice),
|| {
if df.height() == 0 {
return Ok(df);
}

match self.options.maintain_order {
true => df.unique_stable(subset, keep, self.options.slice),
false => df.unique(subset, keep, self.options.slice),
}
},
Cow::Borrowed("unique()"),
)
Expand Down
5 changes: 3 additions & 2 deletions py-polars/tests/unit/test_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,6 @@ def test_empty_is_in() -> None:
)


def test_empty_to_empty() -> None:
assert pl.DataFrame().drop_nulls().shape == (0, 0)
@pytest.mark.parametrize("method", ["drop_nulls", "unique"])
def test_empty_to_empty(method: str) -> None:
assert getattr(pl.DataFrame(), method)().shape == (0, 0)

0 comments on commit 993cc99

Please sign in to comment.