Repository navigation
Conversation
…eld kernel The struct_field kernel accepts a FieldRef in StructFieldOptions, but the compute documentation only described the sequence-of-indices form. Document that the reference can be a FieldPath of child indices, a field name, or a nested sequence of these, with field-name examples added alongside the existing index examples. Also fix the union example, which referred to a child array "a" that does not exist in the sparse_union type used there.
…tioned dataset When writing a partitioned dataset with pq.write_to_dataset, the partition columns are not stored in the data files (they are encoded in the directory names). The collected file metadata therefore has a schema without those columns, and calling pq.write_metadata with the full table schema for the _metadata file fails with "AppendRowGroups requires equal schemas". Add an example to the "Writing _metadata and _common_metadata files" section showing how to write the metadata files for a partitioned dataset: the _common_metadata file gets the full dataset schema, while the partition columns need to be removed from the schema passed for the _metadata file. The example was verified with pyarrow 24.
…cceed when possible Zero-copy conversion of a Table or RecordBatch into a pandas DataFrame was always failing with "Cannot do zero copy conversion into multi-column DataFrame block": in the consolidated-block path (split_blocks=False), allow_zero_copy_blocks is never enabled, so the zero-copy check raises even for a single column. When zero_copy_only=True is requested, convert the columns as separate pandas blocks (as if split_blocks=True had been given): a multi-column block cannot reference the original Arrow memory, while per-column blocks can. Conversions that genuinely need to copy still raise ArrowInvalid (e.g. columns with nulls, or strings_to_categorical / categories). Documented the behavior in the zero_copy_only parameter description and added regression tests.
sameer727
requested review from
AlenkaF,
pitrou,
raulcd and
rok
as code owners
November 22, 2026 18:19
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.
Rationale for this change
Table.to_pandas(zero_copy_only=True)always fails withArrowInvalid: Cannot do zero copy conversion into multi-column DataFrame block, even for a single numeric column (#39194). In the consolidated-block path (split_blocks=False),allow_zero_copy_blocksis never enabled, so the zero-copy check in the pandas conversion always raises.What changes are included in this PR?
When
zero_copy_only=Trueis requested for a Table or RecordBatch conversion, the columns are converted as separate pandas blocks (as ifsplit_blocks=Truehad been given): a multi-column block cannot reference the original Arrow memory, while per-column blocks can.Conversions that genuinely need to copy still raise
ArrowInvalid, e.g. columns with nulls (Needed to copy 1 chunks with 1 nulls, but zero_copy_only was True),strings_to_categorical=True/categories(Need to dictionary encode a column, but only zero-copy conversions allowed).The
zero_copy_onlyparameter docstring was updated to describe this, and regression tests were added toTestZeroCopyConversion.Are these changes tested?
Yes, locally with pyarrow 24.0.0 + pandas 3.0.2 (Windows, Python 3.13): the change is pure Python (
pandas_compat.py), so the modifiedtable_to_dataframewas exercised directly against the installed wheel:pa.table({'a': [1.0, 2.0, 3.0], 'b': [4.0, 5.0, 6.0]}).to_pandas(zero_copy_only=True)now succeeds (previously raised);strings_to_categorical=True,categories=[...];zero_copy_only=False) path and the Series/ChunkedArray path are unchanged; the resulting block layout is per-column only whenzero_copy_only=Trueis requested;pd.read_parquet/pyarrow.datasetread paths behave as before.The three new tests in
python/pyarrow/tests/test_pandas.py(success, copy-needed failure, strings_to_categorical failure) were run locally against the wheel (15 passed in the zero-copy test class).Are there any user-facing changes?
Table.to_pandas(zero_copy_only=True)/RecordBatch.to_pandas(zero_copy_only=True)now succeed instead of always raising. Withzero_copy_only=Truethe resulting DataFrame uses one pandas block per column (this is what makes zero-copy possible; previouslysplit_blocks=Truehad to be passed manually for this).Was AI used for this PR?
In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.
PR code and description written by:
Reviewed before submission by:
This PR was prepared with an AI coding agent (ZCode) at the direction of the submitter. The C++ conversion path (
arrow_to_pandas.cc) was traced to identify the root cause (allow_zero_copy_blocksonly being enabled whensplit_blocks=True), the Python-side fix was verified by execution against the installed pyarrow 24.0.0 wheel (details above), and the change is confined topandas_compat.pyplus docs/tests.