Skip to content

Commit

Permalink
fix: Crash using empty Series in LazyFrame.select() (#16592)
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion authored May 30, 2024
1 parent fc4a00b commit aa771aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/polars-plan/src/logical_plan/lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ impl Hash for LiteralValue {
s.null_count().hash(state);
const RANDOM: u64 = 0x2c194fa5df32a367;
let mut rng = (len as u64) ^ RANDOM;
for _ in 0..5 {
for _ in 0..std::cmp::min(5, len) {
let idx = hash_to_partition(rng, len);
s.get(idx).unwrap().hash(state);
rng = rng.rotate_right(17).wrapping_add(RANDOM);
Expand Down
6 changes: 6 additions & 0 deletions py-polars/tests/unit/test_cse.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,3 +774,9 @@ def test_nested_cache_no_panic_16553() -> None:
assert pl.LazyFrame().select(a=[[[1]]]).collect(comm_subexpr_elim=True).to_dict(
as_series=False
) == {"a": [[[[1]]]]}


def test_hash_empty_series_16577() -> None:
s = pl.Series(values=None)
out = pl.LazyFrame().select(s).collect()
assert out.equals(s.to_frame())

0 comments on commit aa771aa

Please sign in to comment.