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(rust): Fix null handling in collect_statistics of parquet reader #20362

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions crates/polars-io/src/parquet/read/predicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ pub(crate) fn collect_statistics(
let stats = schema
.iter_values()
.map(|field| {
let iter = md.columns_under_root_iter(&field.name).unwrap();

Ok(if iter.len() == 0 {
ColumnStats::new(field.into(), None, None, None)
} else {
ColumnStats::from_arrow_stats(deserialize(field, iter)?, field)
let iter = md.columns_under_root_iter(&field.name);
Ok(match iter {
Some(x) if { x.len() > 0 } => {
ColumnStats::from_arrow_stats(deserialize(field, x)?, field)
},
_ => ColumnStats::new(field.into(), None, None, None),
})
})
.collect::<PolarsResult<Vec<_>>>()?;
Expand Down
21 changes: 21 additions & 0 deletions py-polars/tests/unit/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2710,3 +2710,24 @@ def test_boolean_slice_pushdown_20314() -> None:

f.seek(0)
assert pl.scan_parquet(f).slice(2, 1).collect().item()


def test_allow_missing_columns_predicate_pushdown_20361() -> None:
f1 = io.BytesIO()
f2 = io.BytesIO()

pl.DataFrame({"a": [1, 2], "b": [1, 3], "c": [False, False]}).write_parquet(f1)
pl.DataFrame({"a": [4, 5], "c": [True, False]}).write_parquet(f2)

f1.seek(0)
f2.seek(0)

df = (
pl.scan_parquet([f1, f2], allow_missing_columns=True) # type: ignore[arg-type]
.filter((pl.col.a == pl.col.b) | pl.col.c)
.collect()
)

assert_frame_equal(
df, pl.DataFrame({"a": [1, 4], "b": [1, None], "c": [False, True]})
)
Loading