Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix assertion panic on LazyFrame scratch.is_empty() #20219

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ pub fn pushdown_eligibility(
expr_arena: &mut Arena<AExpr>,
scratch: &mut UnitVec<Node>,
) -> PolarsResult<(PushdownEligibility, PlHashMap<PlSmallStr, PlSmallStr>)> {
assert!(scratch.is_empty());
debug_assert!(scratch.is_empty());
scratch.clear();
let ae_nodes_stack = scratch;

let mut alias_to_col_map =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mod inner {
}

pub fn nodes_scratch_mut(&mut self) -> &mut UnitVec<Node> {
self.scratch.clear();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

&mut self.scratch
}
}
Expand All @@ -49,7 +50,8 @@ fn can_pushdown_slice_past_projections(
arena: &Arena<AExpr>,
scratch: &mut UnitVec<Node>,
) -> (bool, bool) {
assert!(scratch.is_empty());
debug_assert!(scratch.is_empty());
scratch.clear();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this only panic in debug builds, and in release we clear it


let mut can_pushdown_and_any_expr_has_column = false;

Expand Down
12 changes: 12 additions & 0 deletions py-polars/tests/unit/operations/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,15 @@ def test_slice_after_sort_with_nulls_20079() -> None:
out = df.sort("a", nulls_last=False).slice(0, 10).collect()
expected = pl.DataFrame({"a": [None, None, 1.2]})
assert_frame_equal(out, expected)


def test_slice_pushdown_panic_20216() -> None:
col = pl.col("A")

df = pl.LazyFrame({"A": "1/1"})
df = df.with_columns(col.str.split("/"))
df = df.with_columns(
pl.when(col.is_not_null()).then(col.list.get(0)).otherwise(None)
)

assert_frame_equal(df.collect(), pl.DataFrame({"A": ["1"]}))
Loading