Repository navigation
Conversation
|
|
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).
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).
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).
d3f0fb7 to
a78bedf
Compare
29a6b0b to
fb3204a
Compare
|
Given there were changes in the data types PR you might want to rebase or merge them here @AlenkaF. |
e8779e3 to
300602b
Compare
|
Oh, should have squashed, sorry. |
300602b to
bc6a844
Compare
| 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) |
There was a problem hiding this comment.
Note to myself: add assert_type checks once the scalar stubs land.
|
|
||
| # =============================== Aggregations ======================================== | ||
| def all( | ||
| array: BooleanScalar | _ArrayOrChunkedArray | Expression, |
There was a problem hiding this comment.
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.
…ons but also individual functions)
… clean up the tests
9e74943 to
09e4f08
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved type-stub mismatches reject valid runtime calls, accept unsupported argument types, and incorrectly describe supported return types.
8 open issues
Restrict registration in_types to dict · New Allow Schema as register_tabular_function out_type · New Use the correct options types for split and regex-span kernels · New Match make_struct keyword types to MakeStructOptions · New Annotate subsecond results as float64 · New Add options-only overloads and accept dictionary options · New Include ChunkedArray in the return type · New Include list-scalar results for scalar list_slice inputs · New
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
| 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) |
| k: int, | ||
| sort_keys: Sequence[_SortKey], | ||
| *, | ||
| options: SelectKOptions | None = None, |
There was a problem hiding this comment.
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: ... |

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.