Skip to content

GH-55590: [Python][Annotations] Add type annotations for scalars - #55592

Open
rok wants to merge 2 commits into
apache:mainfrom
rok:pyarrow-stubs-scalar
Open

rok wants to merge 2 commits into
apache:mainfrom
rok:pyarrow-stubs-scalar

Conversation

@rok

@rok rok commented Nov 13, 2026

Copy link
Copy Markdown
Member

Rationale for this change

Closes: #55590

What changes are included in this PR?

Adds type annotation stubs for the scalar module: Scalar, its subclasses, NA and pyarrow.scalar(). Indexing an Array or ChunkedArray now returns a Scalar for an index and an array for a slice. Includes annotation tests for scalars.

Are these changes tested?

Yes, by the type annotation tests in pyarrow-stubs-tests and by CI.

Are there any user-facing changes?

Scalars will be type annotated.

Was AI used for this PR?

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

rok and others added 2 commits November 13, 2026 14:41
Squashed history of the pyarrow-stubs-pr3-core-data-sans-generic branch:
the internal type system stubs, the stubs of the core data structures
(arrays, tables, tensors, builders, memory, devices, config and types),
the type annotation tests in pyarrow-stubs-tests, stubtest, and the
pinned type checking environment with the python-stubs pre-commit hooks.

Co-authored-by: AlenkaF <[email protected]>
Co-authored-by: Tadeja Kadunc <[email protected]>
Co-authored-by: Dan Redding <[email protected]>
Co-authored-by: Joris Van den Bossche <[email protected]>
Replace the scalar.pyi placeholder with annotations for Scalar, its
subclasses, NA and pyarrow.scalar(), following the conventions of the
other stubs: plain classes instead of generics, the class hierarchy of
the runtime (e.g. StringScalar is a BinaryScalar, the extension scalars
are ExtensionScalars, ListScalar is a Sequence and StructScalar a
Mapping), and concrete return types for as_py() and the value
properties.

Array and ChunkedArray now return real Scalar types from indexing,
iteration, sum() and index(), so a ChunkedArray is no longer accepted as
the mask of pyarrow.array(). Their __getitem__ gets two overloads, so
that an index returns a Scalar and a slice an array, instead of a union
of both. Add annotation tests for the scalars.
Copilot AI balanced review requested due to automatic review settings November 13, 2026 13:43

This comment was marked as low quality.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #55590 has no components, please add labels for components.

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][Annotations] Add type annotations for scalars

2 participants