Skip to content

GH-51260: [Python][CI] Enable the numpydoc PR02 check and fix its violations - #55728

Closed
sameer727 wants to merge 4 commits into
apache:mainfrom
sameer727:numpydoc-enable-pr02-51260
Closed

sameer727 wants to merge 4 commits into
apache:mainfrom
sameer727:numpydoc-enable-pr02-51260

Conversation

@sameer727

Copy link
Copy Markdown

Rationale for this change

The numpydoc validation run (archery numpydoc --allow-rule GL10,PR01,PR03,PR04,PR05,PR10,RT03,YD01 in the conda-python-docs job) never reports PR02 (Unknown parameters), so parameters that are documented in a docstring but absent from the actual signature go unnoticed (#51260). Additionally, the PR02/PR03 comparison only happens when numpydoc can introspect the signature, which for cython generated callables depends on archery parsing the signature from the first docstring line — a step that currently fails for several objects and silently disables the parameter checks for them.

What changes are included in this PR?

  1. archery signature parsing (dev/archery/archery/lang/python.py):
    • skip parameter annotations (not supported by CPython's _signature_fromstr), e.g. retry_strategy: S3RetryStrategy = AwsStandardS3RetryStrategy(max_attempts=3) in S3FileSystem;
    • drop a trailing bare keyword-only marker, e.g. LocalFileSystem(use_mmap=False, *);
    • when parsing still fails because a default value is not a constant expression, retry without the default values — the parameter names, kinds and order are what matter for the docstring validation;
    • when the signature cannot be determined at all (e.g. docstrings without an embedded signature line like ParquetEncryptionConfig), skip the PR01/PR02/PR03 rules instead of comparing the documented parameters against an empty signature, which would report every documented parameter as unknown.
  2. python/pyarrow/parquet/core.py: ParquetWriter documents coerce_timestamps, allow_truncated_timestamps and data_page_size, but they were only accepted via **options; they are now explicit parameters, matching write_table. read_pandas reused the read_table docstring template and documented all of read_table's **kwargs options as if they were its own parameters; it now has a docstring for its own parameters, pointing to read_table for the rest.
  3. python/pyarrow/_s3fs.pyx: reorder the S3FileSystem docstring parameters to match the __init__ signature order (PR03).
  4. compose.yaml: enable PR02 in the validation run.

Are these changes tested?

  • New unit tests for the parsing in dev/archery/archery/tests/test_numpydoc.py (9 tests, run locally).
  • The full validation was run locally with archery numpydoc --allow-rule GL10,PR01,PR02,PR03,PR04,PR05,PR10,RT03,YD01 against an installed pyarrow 24.0.0 wheel whose pure-Python modules were overlaid with this PR's versions: PR02 violations go from 6 objects to 0. (ParquetEncryptionConfig/ParquetDecryptionConfig/OSFile use the new skip-when-undeterminable behavior; S3FileSystem/LocalFileSystem parse after the parser fixes; read_pandas/ParquetWriter are fixed in this PR. The remaining locally-reported PR03 items are pre-existing allowed-rule noise: one comes from the pyarrow 24 wheel's baked-in S3FileSystem docstring, which this PR reorders in _s3fs.pyx for main, and one from ParquetWriter, whose docstring order differs from the signature — same as for write_table.)
  • The changed ParquetWriter parameters were verified functionally by writing Parquet files with coerce_timestamps='ms', allow_truncated_timestamps, data_page_size, the legacy **options path (metadata_collector) and no arguments, and reading the metadata back.

Are there any user-facing changes?

  • ParquetWriter accepts coerce_timestamps, allow_truncated_timestamps and data_page_size as explicit keyword arguments (they previously worked via **options).
  • read_pandas' rendered docstring now documents its own parameters; the available options are documented in read_table, to which **kwargs are passed.
  • Docstrings with parameters that don't exist in the signature will now be reported by the numpydoc CI job.

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 root causes were identified by running the archery numpydoc validation locally against an installed pyarrow wheel (reproducing the violations from the issue), and every change was verified locally: the parser fixes by unit tests and by parsing the real objects (S3FileSystem, LocalFileSystem), the ParquetWriter change by writing/reading files with the affected parameters, and the overall effect by the validation run going from 6 PR02 violations to 0.

…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.
The archery numpydoc validation currently only reports a fixed set of
rules (--allow-rule ...), and PR02 (Unknown parameters) is not part of
it, so parameters documented in a docstring but absent from the actual
signature are never reported. Also, numpydoc only compares documented
parameters against the signature when it can introspect the latter,
which for cython generated callables depends on parsing the signature
from the first docstring line.

Fix the signature parsing in archery so that more cython signatures
become introspectable:

- skip parameter annotations (e.g. "retry_strategy: S3RetryStrategy =
  AwsStandardS3RetryStrategy(max_attempts=3)" in S3FileSystem), which
  _signature_fromstr does not support
- drop a trailing bare keyword-only marker, e.g.
  LocalFileSystem(use_mmap=False, *)
- if parsing still fails because a default value is not a constant
  expression, retry without the default values, as the parameter names,
  kinds and order are what matter for the docstring validation

When the signature cannot be determined at all (e.g. the docstring has
no embedded signature line, like ParquetEncryptionConfig), skip the
PR01/PR02/PR03 rules instead of comparing against an empty signature,
which would report every documented parameter as unknown.

Fix the violations that remain once PR02 is reported:

- ParquetWriter documents coerce_timestamps, allow_truncated_timestamps
  and data_page_size, but they were only accepted via **options; make
  them explicit parameters instead, matching write_table
- read_pandas reused the read_table docstring template, documenting all
  of read_table's parameters that are only accepted via **kwargs; give
  it a docstring for its own parameters instead
- reorder the S3FileSystem docstring parameters to match the __init__
  signature order (PR03)

Finally enable PR02 in the validation run of the conda-python-docs job.

The changes were verified locally by running the validation against an
installed pyarrow wheel overlaid with the pure-Python modules (PR02
violations go from 6 to 0) and by writing/reading Parquet files with
the changed ParquetWriter parameters. The new archery parsing is unit
tested in dev/archery/archery/tests/test_numpydoc.py.
Copilot AI balanced review requested due to automatic review settings November 22, 2026 18:46

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.

@thisisnic

Copy link
Copy Markdown
Member

Closing this PR as it doesn't meet our guidelines on AI-generated contributions:

https://arrow.apache.org/docs/developers/overview.html#ai-generated-code

If you'd like to contribute this change, please review and test the code yourself, then open a new PR.

@thisisnic thisisnic closed this Nov 27, 2026
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.

3 participants