fix: Inconsistent schemas when converting to pyarrow#1315
Merged
timsaucer merged 4 commits intoapache:mainfrom Jan 5, 2026
Merged
fix: Inconsistent schemas when converting to pyarrow#1315timsaucer merged 4 commits intoapache:mainfrom
timsaucer merged 4 commits intoapache:mainfrom
Conversation
kosiew
reviewed
Dec 3, 2025
Comment on lines
+1870
to
+1881
| def test_parquet_non_null_column_to_pyarrow(ctx, tmp_path): | ||
| path = tmp_path.joinpath("t.parquet") | ||
|
|
||
| ctx.sql("create table t_(a int not null)").collect() | ||
| ctx.sql("insert into t_ values (1), (2), (3)").collect() | ||
| ctx.sql(f"copy (select * from t_) to '{path}'").collect() | ||
|
|
||
| ctx.register_parquet("t", path) | ||
| pyarrow_table = ctx.sql("select max(a) as m from t").to_arrow_table() | ||
| assert pyarrow_table.to_pydict() == {"m": [3]} | ||
|
|
||
|
|
Contributor
There was a problem hiding this comment.
I think we should also add
- a regression test for the empty-batch case to ensure when there are zero record batches the DataFrame schema is still applied (because that’s the behavior the code has preserved).
- a test covering an edge-case where an aggregation yields a NULL (e.g., max on an empty input) and ensure to_arrow_table correctly represents that ensures we didn't hide other nullability issues
Contributor
Author
There was a problem hiding this comment.
Good call, I've added those two new tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #1314.
Rationale for this change
Allow the conversion of batches to
pyarrowwhen there are inconsistencies with theDataFrame's schema (i.e., on the nullability of columns).What changes are included in this PR?
pyarrownow uses theRecordBatch's own schema instead of theDataFrame's (when possible): https://arrow.apache.org/docs/python/generated/pyarrow.Table.html#pyarrow.Table.from_batches.Are there any user-facing changes?
No.