Skip to content

GH-27905: [Python][Dataset] Document dataset schema inference - #55942

Open
kukanggg89 wants to merge 1 commit into
apache:mainfrom
kukanggg89:arrow-27905-dataset-schema-docs
Open

kukanggg89 wants to merge 1 commit into
apache:mainfrom
kukanggg89:arrow-27905-dataset-schema-docs

Conversation

@kukanggg89

@kukanggg89 kukanggg89 commented Dec 3, 2026 •

Copy link
Copy Markdown

Rationale for this change

ds.dataset() infers the dataset schema from a single fragment when no schema is passed. A column that is all null in that fragment becomes null-typed for the whole dataset, and reading files where the column has values then fails with an ArrowTypeError. AlenkaF approved documenting this instead of changing the behavior in #27905.

What changes are included in this PR?

  • python/pyarrow/dataset.py: the schema parameter of dataset() now notes the schema is inferred from a single fragment only, and that passing schema explicitly avoids the null-column problem.
  • docs/source/python/dataset.rst: a note plus a short example after the schema inference paragraph, showing a null-typed column from the first file and the same dataset with an explicit string schema.

Are these changes tested?

I did not run the test suite or the docs doctests here: this environment has no pyarrow install and the package needs the built C++ library. What I did check: python -m py_compile passes on the edited dataset.py, the example code parses, and the claims match the C++ source (InspectOptions in cpp/src/arrow/dataset/discovery.h defaults to inspecting one fragment) and the repro in #27905. The guide example still needs the docs build in CI to confirm it runs.

Are there any user-facing changes?

Yes. The dataset() docstring and the Dataset guide now document the schema inference behavior and the schema= workaround. No code behavior changes.

Was AI used for this PR?

Drafted with help from Claude. I reviewed and revised every change myself before opening this PR.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Document that ds.dataset() infers the dataset schema from a single fragment only, so an all-null column in that fragment becomes null-typed for the whole dataset and scanning other files can fail with an ArrowTypeError. Adds a note to the schema parameter and a short example to the Dataset guide.

Assisted-by: Muse
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.

[Python][Dataset] The first table schema becomes a common schema for the full Dataset

1 participant