Skip to content

Commit

Permalink
fix: Fix serialization of empty DF in LazyFrame (#20658)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Jan 10, 2025
1 parent d5b6719 commit c9c34ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/polars-core/src/serde/df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ impl DataFrame {
})
.collect::<PolarsResult<Vec<DataFrame>>>()?;

if dfs.is_empty() {
return Ok(DataFrame::empty());
}
let mut df = accumulate_dataframes_vertical_unchecked(dfs);

// Set custom metadata (fallible)
Expand Down
8 changes: 8 additions & 0 deletions py-polars/tests/unit/test_serde.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,11 @@ def test_serde_udf() -> None:
result = pl.LazyFrame.deserialize(io.BytesIO(lf.serialize()))

assert_frame_equal(lf, result)


def test_serde_empty_df_lazy_frame() -> None:
lf = pl.LazyFrame()
f = io.BytesIO()
f.write(lf.serialize())
f.seek(0)
assert pl.LazyFrame.deserialize(f).collect().shape == (0, 0)

0 comments on commit c9c34ae

Please sign in to comment.