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: Reading Parquet with Null dictionary page #18112

Merged
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
2 changes: 2 additions & 0 deletions crates/polars-parquet/src/arrow/read/deserialize/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ pub fn iter_to_arrays(
data_type: ArrowDataType,
mut filter: Option<Filter>,
) -> ParquetResult<Box<dyn Array>> {
_ = iter.read_dict_page()?;

let num_rows = Filter::opt_num_rows(&filter, iter.total_num_values());

let mut len = 0usize;
Expand Down
14 changes: 8 additions & 6 deletions crates/polars-parquet/src/parquet/read/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,14 @@ impl Iterator for BasicDecompressor {
Some(Ok(p)) => p,
};

Some(decompress(page, &mut self.buffer).map(|p| {
if let Page::Data(p) = p {
p
} else {
panic!("Found compressed page in the middle of the pages")
}
Some(decompress(page, &mut self.buffer).and_then(|p| {
let Page::Data(p) = p else {
return Err(ParquetError::oos(
"Found dictionary page beyond the first page of a column chunk",
));
};

Ok(p)
}))
}

Expand Down
14 changes: 14 additions & 0 deletions py-polars/tests/unit/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,3 +1400,17 @@ def test_write_sliced_lists_18069() -> None:
after = pl.read_parquet(f)

assert_frame_equal(before, after)


def test_null_array_dict_pages_18085() -> None:
test = pd.DataFrame(
[
{"A": float("NaN"), "B": 3, "C": None},
{"A": float("NaN"), "B": None, "C": None},
]
)

f = io.BytesIO()
test.to_parquet(f)
f.seek(0)
pl.read_parquet(f)