Skip to content

GH-31678: [Docs][Python] Document writing _metadata for a partitioned dataset - #55726

Open
sameer727 wants to merge 2 commits into
apache:mainfrom
sameer727:doc-partitioned-metadata-31678
Open

sameer727 wants to merge 2 commits into
apache:mainfrom
sameer727:doc-partitioned-metadata-31678

Conversation

@sameer727

@sameer727 sameer727 commented Nov 22, 2026 •

Copy link
Copy Markdown

Rationale for this change

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). Calling pq.write_metadata with the full table schema for the _metadata file fails with "AppendRowGroups requires equal schemas" (#31678). As suggested in the issue, this adds a partitioned example to the docs.

What changes are included in this PR?

  • New partitioned example in the "Writing _metadata and _common_metadata files" section of the Python parquet docs, showing that:
    • _common_metadata is written with the full dataset schema (including the partition columns),
    • the partition columns need to be removed from the schema passed for the _metadata file.

Are these changes tested?

Documentation-only change; no code behavior changes. The exact example was verified by running it locally with pyarrow 24.0.0: writing a two-column-partitioned dataset, writing both metadata files, and reading the dataset back with pq.ParquetDataset and pyarrow.dataset.dataset (partition columns are restored from the directory structure on read).

Are there any user-facing changes?

Documentation only.

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:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

This PR was prepared with an AI coding agent (ZCode) at the direction of the submitter. The docs example was verified by execution locally (see "Are these changes tested?").

…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.
@sameer727
sameer727 requested a review from pitrou as a code owner November 22, 2026 18:04
Copilot AI balanced review requested due to automatic review settings November 22, 2026 18:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants