Skip to content

Commit

Permalink
fix: Don't deduplicate sort that has slice pushdown (#15784)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Apr 19, 2024
1 parent e2845ae commit 4a870cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ impl OptimizationRule for SimpleProjectionAndCollapse {
slice,
sort_options,
} => match lp_arena.get(*input) {
Sort { input: inner, .. } => Some(Sort {
Sort {
input: inner,
slice: None,
..
} => Some(Sort {
input: *inner,
by_column: by_column.clone(),
slice: *slice,
Expand Down
6 changes: 6 additions & 0 deletions py-polars/tests/unit/operations/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,9 @@ def test_slice_lazy_frame_raises_proper(input_slice: tuple[int | None]) -> None:
s = slice(*input_slice)
with pytest.raises(ValueError, match="not supported"):
ldf[s].collect()


def test_double_sort_slice_pushdown_15779() -> None:
assert (
pl.LazyFrame({"foo": [1, 2]}).sort("foo").head(0).sort("foo").collect()
).shape == (0, 1)

0 comments on commit 4a870cc

Please sign in to comment.