Skip to content

GH-49194: [Python][Annotations] Compute module - #49201

Open
rok wants to merge 23 commits into
apache:mainfrom
rok:pyarrow-stubs-pr4-compute
Open

rok wants to merge 23 commits into
apache:mainfrom
rok:pyarrow-stubs-pr4-compute

Conversation

@rok

@rok rok commented Feb 9, 2026 •

Copy link
Copy Markdown
Member

Rationale for this change

Closes: #49194

What changes are included in this PR?

Adds type annotation stubs for compute, _compute, _compute_docstring, and _acero modules. Includes source fixes in compute.py and acero.py, and type-ignore annotations in related tests.

Are these changes tested?

Yes, by CI.

Are there any user-facing changes?

Compute module functions will be type annotated.

@github-actions

github-actions Bot commented Feb 9, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #49194 has been automatically assigned in GitHub to PR creator.

rok added a commit to rok/arrow that referenced this pull request Nov 13, 2026
Add type annotation stubs for compute, _compute, _compute_docstring,
and _acero modules.

These are the stubs of apacheGH-49201 as they were, at their original paths.
The type checker accommodations that apacheGH-49201 made in compute.py,
acero.py and the PyArrow tests are left out, as the type checkers no
longer run on pyarrow/ (see apacheGH-55264).
rok added a commit to rok/arrow that referenced this pull request Nov 13, 2026
Add type annotation stubs for compute, _compute, _compute_docstring,
and _acero modules.

These are the stubs of apacheGH-49201 as they were, at their original paths.
The type checker accommodations that apacheGH-49201 made in compute.py,
acero.py and the PyArrow tests are left out, as the type checkers no
longer run on pyarrow/ (see apacheGH-55264).
rok added a commit to rok/arrow that referenced this pull request Nov 13, 2026
Add type annotation stubs for compute, _compute, _compute_docstring,
and _acero modules.

These are the stubs of apacheGH-49201 as they were, at their original paths.
The type checker accommodations that apacheGH-49201 made in compute.py,
acero.py and the PyArrow tests are left out, as the type checkers no
longer run on pyarrow/ (see apacheGH-55264).
@rok
rok force-pushed the pyarrow-stubs-pr4-compute branch from d3f0fb7 to a78bedf Compare November 13, 2026 13:06
@rok
rok force-pushed the pyarrow-stubs-pr4-compute branch 2 times, most recently from 29a6b0b to fb3204a Compare November 13, 2026 13:29
@rok

rok commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Given there were changes in the data types PR you might want to rebase or merge them here @AlenkaF.

@AlenkaF
AlenkaF force-pushed the pyarrow-stubs-pr4-compute branch from e8779e3 to 300602b Compare November 18, 2026 05:21
@AlenkaF

AlenkaF commented Nov 18, 2026

Copy link
Copy Markdown
Member

Oh, should have squashed, sorry.

Comment thread python/pyarrow-stubs/_stubs_typing.pyi Resolved
Comment thread python/pyarrow-stubs/_stubs_typing.pyi Resolved
Comment thread python/pyarrow-stubs/_compute.pyi Resolved
@AlenkaF
AlenkaF force-pushed the pyarrow-stubs-pr4-compute branch from 300602b to bc6a844 Compare November 19, 2026 09:19
check(assert_type(field.equals(pc.field("a")), bool), bool)

# Calling a compute function with an expression builds an expression.
check(pc.count(field), pc.Expression)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note to myself: add assert_type checks once the scalar stubs land.

Comment thread python/pyarrow-stubs/compute.pyi Outdated

# =============================== Aggregations ========================================
def all(
array: BooleanScalar | _ArrayOrChunkedArray | Expression,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To be consistent with decisions made in array.pyi we should use general Scalar class in parameters, not narrow types like BooleanScalar and aliases like _NumericScalar. The narrow types stay for returns.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@AlenkaF
AlenkaF force-pushed the pyarrow-stubs-pr4-compute branch from 9e74943 to 09e4f08 Compare November 26, 2026 04:48
@AlenkaF
AlenkaF marked this pull request as ready for review November 26, 2026 05:08
@AlenkaF
AlenkaF requested a review from raulcd as a code owner November 26, 2026 05:08
Copilot AI balanced review requested due to automatic review settings November 26, 2026 05:08

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.

🟡 Changes recommended

Unresolved type-stub mismatches reject valid runtime calls, accept unsupported argument types, and incorrectly describe supported return types.

8 open issues
What changed in this PR

This PR advances GH-49194 by adding compute and Acero type stubs to PyArrow’s annotation coverage.

Changes:

  • Adds signatures for compute functions, options, expressions, user-defined functions, and Acero execution nodes.
  • Adds annotation tests and updates type-checker configuration and stubtest exceptions.
  • Corrects documentation for accepted value sets and serialization return types.
File Description
python/​pyproject.toml Enables compute type checking and adjusts override rules.
python/​pyarrow/​_substrait.pyx Documents the memoryview serialization result.
python/​pyarrow/​_compute.pyx Corrects value-set and serialization documentation.
python/​pyarrow-stubs/​compute.pyi Adds public compute function signatures and exports.
python/​pyarrow-stubs/​_compute.pyi Defines compute classes, options, expressions, and registration APIs.
python/​pyarrow-stubs/​_acero.pyi Adds execution-plan and node-option signatures.
python/​pyarrow-stubs-tests/​test_compute.py Adds static and runtime compute annotation checks.
python/​pyarrow-stubs-tests/​test_acero.py Adds declaration and aggregation annotation checks.
python/​pyarrow-stubs-tests/​stubtest_allowlist.txt Allows compute extension constructor signature differences.
.pre-commit-config.yaml Updates the comment’s example of an unannotated module.

Review effort: Balanced

Comment thread python/pyarrow-stubs/_compute.pyi Resolved
Comment thread python/pyarrow-stubs/_compute.pyi Resolved
Comment thread python/pyarrow-stubs/compute.pyi Resolved
Comment on lines +1160 to +1161
field_nullability: bool | None = None,
field_metadata: Sequence[KeyValueMetadata] | None = None,
nanosecond = _clone_signature(hour)
quarter = _clone_signature(day)
second = _clone_signature(hour)
subsecond = _clone_signature(hour)
Comment on lines +1566 to +1569
k: int,
sort_keys: Sequence[_SortKey],
*,
options: SelectKOptions | None = None,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Dictionary as an option works at runtime but is not documented and would make the parameter type too broad in my opinion.

As for the required parameters where instead an option class could be passed, yeah that is a downside of simple annotations which I would take for now. We can open a follow-up to add overloads (2 overloads each, approx 26 functions) to make this more useful.

/,
*,
memory_pool: MemoryPool | None = None,
) -> BooleanScalar | BooleanArray | Expression: ...
*,
options: ListSliceOptions | None = None,
memory_pool: MemoryPool | None = None,
) -> BaseListArray | ChunkedArray | Expression: ...
Copilot AI balanced review requested due to automatic review settings November 27, 2026 05:36

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.

Copilot AI balanced review requested due to automatic review settings November 27, 2026 05:41

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.

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] Compute module

4 participants