Skip to content

Commit

Permalink
negative slice fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion committed Mar 3, 2025
1 parent 965d996 commit 50b907c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/polars-stream/src/nodes/negative_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ impl ComputeNode for NegativeSliceNode {
signed_start_offset -= len as i64;
}

while buffer.total_len as i64 - buffer.frames.back().unwrap().height() as i64
> signed_stop_offset
while !buffer.frames.is_empty()
&& buffer.total_len as i64 - buffer.frames.back().unwrap().height() as i64
> signed_stop_offset
{
buffer.total_len -= buffer.frames.pop_back().unwrap().height();
}
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 @@ -310,3 +310,9 @@ def test_slice_pushdown_panic_20216() -> None:

assert_frame_equal(q.slice(0, 1).collect(), pl.DataFrame({"A": ["1"]}))
assert_frame_equal(q.collect(), pl.DataFrame({"A": ["1"]}))


def test_slice_empty_morsel_input() -> None:
q = pl.LazyFrame({"a": []})
assert_frame_equal(q.slice(999, 3).slice(999, 3).collect(), q.collect().clear())
assert_frame_equal(q.slice(-999, 3).slice(-999, 3).collect(), q.collect().clear())

0 comments on commit 50b907c

Please sign in to comment.