Skip to content

Conversation

@rok
Copy link
Owner

@rok rok commented Jul 28, 2025

NOTE: this is preliminary prototype work to be used for discussion and not ready to merge to arrow/main.

This adds pyarrow-stubs into arrow monorepo, fixes some type annotation issues and adds a rudimentary CI type annotation test.

* Add typing to arrow using stubs

* GH-7: [Python] Fix invalid-context-manager error (#30)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unresolved-reference` error

* Revert "Fix `unresolved-reference` error"

This reverts commit 7ee3d2f.

* Fix invalid-context-manager

---------

Co-authored-by: Patrick J. Roddy <patrickjamesroddy@gmail.com>

* GH-8: [Python] Fix invalid-type-form (#31)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unresolved-reference` error

* Revert "Fix `unresolved-reference` error"

This reverts commit 7ee3d2f.

* Fix invalid-type-form errors

---------

Co-authored-by: Patrick J. Roddy <patrickjamesroddy@gmail.com>

* GH-9: [Python] Fix non-subscriptable error (#32)

* fix: The type parameter of array should be covariant (apache#253)

* release 20.0.0.20250716 (apache#254)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unresolved-reference` error

* Revert "Fix `unresolved-reference` error"

This reverts commit 7ee3d2f.

* Fix non-subscriptable issues

---------

Co-authored-by: Patrick J. Roddy <patrickjamesroddy@gmail.com>

* GH-11: [Python] Fix no-matching-overload error (#34)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unresolved-reference` error

* Revert "Fix `unresolved-reference` error"

This reverts commit 7ee3d2f.

* Fix no-matching-overload

---------

Co-authored-by: Patrick J. Roddy <patrickjamesroddy@gmail.com>

* GH-12: [Python] Fix `invalid-return-type` error (#25)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unresolved-reference` error

* Revert "Fix `unresolved-reference` error"

This reverts commit 7ee3d2f.

* Fix `invalid-return-type` error

* Fix linting

---------

Co-authored-by: Rok Mihevc <rok@mihevc.org>

* GH-14: [Python] Fix `not-iterable` typing (#26)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unresolved-reference` error

* Revert "Fix `unresolved-reference` error"

This reverts commit 7ee3d2f.

* Fix `not-iterable` error

---------

Co-authored-by: Rok Mihevc <rok@mihevc.org>

* GH-15: [Python] Fix possibly-unbound-attribute (#38)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unresolved-reference` error

* Revert "Fix `unresolved-reference` error"

This reverts commit 7ee3d2f.

* Fix possibly-unbound-attribute

---------

Co-authored-by: Patrick J. Roddy <patrickjamesroddy@gmail.com>

* GH-16: [Python] Fix too-many-positional-arguments (#35)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unresolved-reference` error

* Revert "Fix `unresolved-reference` error"

This reverts commit 7ee3d2f.

* Fix too-many-positional-arguments

---------

Co-authored-by: Patrick J. Roddy <patrickjamesroddy@gmail.com>

* GH-17: [Python] Fix unknown-argument (#36)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unresolved-reference` error

* Revert "Fix `unresolved-reference` error"

This reverts commit 7ee3d2f.

* Fix unknown-argument

---------

Co-authored-by: Patrick J. Roddy <patrickjamesroddy@gmail.com>

* GH-18: [Python] Fix unresolved-attribute (#37)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unresolved-reference` error

* Revert "Fix `unresolved-reference` error"

This reverts commit 7ee3d2f.

* Fix unresolved-attribute

---------

Co-authored-by: Patrick J. Roddy <patrickjamesroddy@gmail.com>

* GH-19: [Python] Fix unresolved-global (#39)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unresolved-reference` error

* Revert "Fix `unresolved-reference` error"

This reverts commit 7ee3d2f.

* Fix unresolved-global

---------

Co-authored-by: Patrick J. Roddy <patrickjamesroddy@gmail.com>

* GH-20: [Python] Fix `unsupported-reference` typing (#24)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unresolved-reference` error

* Revert "Fix `unresolved-reference` error"

This reverts commit 7ee3d2f.

* Fix `unresolved-reference` error

---------

Co-authored-by: Rok Mihevc <rok@mihevc.org>

* GH-6: [Python] Fix invalid-argument-type error (#29)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unresolved-reference` error

* Revert "Fix `unresolved-reference` error"

This reverts commit 7ee3d2f.

* removing OrderedDict, etc

---------

Co-authored-by: Patrick J. Roddy <patrickjamesroddy@gmail.com>

* GH-27: [Python] Fix call-non-callable error (#28)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unresolved-reference` error

* Revert "Fix `unresolved-reference` error"

This reverts commit 7ee3d2f.

* to_sparse appears deprecated, ignore inline

* Update python/pyarrow/tests/test_feather.py

---------

Co-authored-by: Patrick J. Roddy <patrickjamesroddy@gmail.com>

* GH-10: [Python] Fix invalid-assignment error (#33)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unresolved-reference` error

* Revert "Fix `unresolved-reference` error"

This reverts commit 7ee3d2f.

* Fix invalid-assignment

---------

Co-authored-by: Patrick J. Roddy <patrickjamesroddy@gmail.com>

* GH-21: [Python] Fix `unsupported-operator` typing (#22)

* Add py.typed file to signify that the library is typed

See the relevant PEP https://peps.python.org/pep-0561

* Prepare `pyarrow-stubs` for history merging

MINOR: [Python] Prepare `pyarrow-stubs` for history merging

Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com>

* Add `ty` configuration and suppress error codes

* One line per rule

* Add licence header from original repo for all `.pyi` files

* Revert "Add licence header from original repo for all `.pyi` files"

This reverts commit 1631f39.

* Prepare for licence merging

* Exclude `stubs` from `rat` test

* Add Apache licence clause to `py.typed`

* Reduce list

* Add `ty` as a step in the action

* Run in the correct directory

* Remove `check` from `pip`

* Fix `unsupported-operator` error

---------

* fix unsupported-operator

* Fix unresolved-reference

* Fix not-iterable

* Fix no-matching-overload

* Fix invalid-assignment

* Fix too-many-positional-arguments

* Fix invalid-argument-type

* Fix missing-argument

* Fix unresolved-import

* Fix possibly-unbound-import

* Fix possibly-unbound-import

* Fix unresolved-attribute

* Revert test changes

* Converging

---------

Co-authored-by: Patrick J. Roddy <patrickjamesroddy@gmail.com>
@rok
Copy link
Owner Author

rok commented Jul 28, 2025

Things that come to mind after working on this:

  • It would be nice to inline as much annotations as possible for maintainability.
  • PR currently copies pyarrow-stubs verbatim, but we would probably want to remove docs from pyi files if possible.

@rok
Copy link
Owner Author

rok commented Jul 28, 2025

@paddyroddy @zen-xu

@rok
Copy link
Owner Author

rok commented Jul 28, 2025

(Cross posting from apache#45919)

Things that come to mind after working on this:

  • It would be nice to inline as much annotations as possible for maintainability.
  • PR currently copies pyarrow-stubs verbatim, but we would probably want to remove docs from pyi files if possible.

@rok
Copy link
Owner Author

rok commented Jul 29, 2025

@kou any thoughts on this?
(it's too early for reviews, just gathering opinions)

@kou
Copy link

kou commented Jul 29, 2025

Thanks for pinging me here.

My random thoughts:

  • If we want to merge this one PR, we may need to follow the ASF IP clearance process. See https://incubator.apache.org/ip-clearance/ and search "Apache Arrow" for the past code donation with IP clearance.
  • If we want to open a PR per file, we can use the usual development process: Open an issue, open a PR for it, review the PR and merge the PR.

@amoeba
Copy link

amoeba commented Jul 30, 2025

Thanks for the work on this @rok. A few thoughts that may be retreading previous discussions:

  • Can we somehow calculate type coverage? At least for the public interfaces.
  • Since inlining annotations is preferred, maybe we should have a section in the PyArrow docs for contributors who might want to help convert stubs to inlined annotations? Is the goal here to inline all type annotations? Should new contributions add stubs or add inline annotations?
  • What's the editor support story here? Do any LSPs pick up stubs?
  • Should we have a precommit for type checking?

@paddyroddy
Copy link
Collaborator

Can we somehow calculate type coverage? At least for the public interfaces.

This seems like it is currently possible with mypy and pyright and a feature request for ty.

@rok
Copy link
Owner Author

rok commented Jul 31, 2025

Thanks for the great questions @amoeba ! I've raised the inlining one in the discussions since we have more eyes there.

  • Can we somehow calculate type coverage? At least for the public interfaces.

Seems like a good idea. I'll check @paddyroddy s suggestion.

  • What's the editor support story here? Do any LSPs pick up stubs?

My pycharm seems to pick up the stubs from the arrow/python/stubs automatically. PEP-561 specifies distribution mechanisms and I expect editors would follow the spec, but I could be wrong.

  • Should we have a precommit for type checking?

That would be nice. We should also include some sort of stub linter, e.g.: flake8-pyi.

@dangotbanned
Copy link

dangotbanned commented Aug 1, 2025

That would be nice. We should also include some sort of stub linter, e.g.: flake8-pyi.

If you're familiar with ruff, there's a flake8-pyi group + some others that help you keep up with new typing features/conventions:

@rok rok changed the title [Python] Add typing to arrow using pyarrow-stubs [Python] Add type checks to Arrow using pyarrow-stubs and initially ignoring failing checks Aug 21, 2025
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.

6 participants