Skip to content

GH-49103: [Python][Annotations] Add internal type system stubs (_types, error, _stubs_typing) - #48622

Open
rok wants to merge 21 commits into
apache:mainfrom
rok:pyarrow-stubs-pr2-core-types
Open

GH-49103: [Python][Annotations] Add internal type system stubs (_types, error, _stubs_typing)#48622
rok wants to merge 21 commits into
apache:mainfrom
rok:pyarrow-stubs-pr2-core-types

Conversation

@rok

@rok rok commented Dec 22, 2025

Copy link
Copy Markdown
Member

Rationale for this change

This is the second in series of PRs adding type annotations to pyarrow and resolving #32609. It builds on top of and should be merged after #48618.

What changes are included in this PR?

This adds:

  • _types.pyi - Core type definitions including
  • _stubs_typing.pyi - Internal typing protocols and helpers used across stub files
  • error.pyi - Exception classes (ArrowException, ArrowInvalid, ArrowIOError, etc.)
  • Minimal placeholder stubs - lib.pyi, io.pyi, scalar.pyi - using __getattr__ to allow imports to resolve while deferring to subsequent PRs

Are these changes tested?

Via CI type checks established in #48618.

Are there any user-facing changes?

Users will start seeing some minimal annotated types.

Comment thread python/pyarrow-stubs/pyarrow/_stubs_typing.pyi Outdated
@rok
rok force-pushed the pyarrow-stubs-pr2-core-types branch from d3c5740 to 27d1c65 Compare January 26, 2026 12:57
@rok

rok commented Jan 26, 2026

Copy link
Copy Markdown
Member Author

I've rebased this on the annotation infra check PR (#48618) to make sure we're on the right track.

@rok
rok force-pushed the pyarrow-stubs-pr2-core-types branch 2 times, most recently from 3f9ed3b to 0ac95b0 Compare January 26, 2026 19:11
@rok rok changed the title GH-32609: [Python] Add internal type system stubs (_types, error, _stubs_typing) GH-49103: [Python] Add internal type system stubs (_types, error, _stubs_typing) Jan 31, 2026
@github-actions

Copy link
Copy Markdown

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

@rok
rok force-pushed the pyarrow-stubs-pr2-core-types branch 3 times, most recently from 7873930 to 43e7cc6 Compare February 9, 2026 19:11
@rok
rok marked this pull request as ready for review February 9, 2026 20:09
@rok
rok force-pushed the pyarrow-stubs-pr2-core-types branch from 51a7a4e to 7bc0a98 Compare February 13, 2026 15:24
@rok
rok force-pushed the pyarrow-stubs-pr2-core-types branch 5 times, most recently from 0d15871 to 8f3796d Compare March 9, 2026 23:51
@rok
rok requested a review from dangotbanned March 10, 2026 00:01
@rok
rok force-pushed the pyarrow-stubs-pr2-core-types branch from 8f3796d to 72571d2 Compare March 10, 2026 13:39
rok and others added 12 commits June 14, 2026 10:06
Co-authored-by: Dan Redding <125183946+dangotbanned@users.noreply.github.com>
Co-authored-by: Dan Redding <125183946+dangotbanned@users.noreply.github.com>
Co-authored-by: Dan Redding <125183946+dangotbanned@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 14, 2026 17:45
@rok
rok force-pushed the pyarrow-stubs-pr2-core-types branch from 99f5809 to 8982d1e Compare June 14, 2026 17:45

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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comment thread python/pyarrow/fs.py Outdated
Comment thread python/pyarrow-stubs/pyarrow/_types.pyi Outdated
Comment thread python/pyarrow-stubs/pyarrow/io.pyi
Comment thread python/pyarrow-stubs/pyarrow/scalar.pyi
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 14, 2026 19:15
@rok
rok requested a review from dangotbanned June 14, 2026 19:15
@rok

rok commented Jun 14, 2026

Copy link
Copy Markdown
Member Author

Finally took some time to work on this again. @dangotbanned I accepted you proposals and added some other changes. Could you please take another look and maybe we can merge?

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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread python/pyarrow-stubs/pyarrow/error.pyi
Comment thread python/pyarrow-stubs/pyarrow/_types.pyi
@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Jun 14, 2026
@github-actions github-actions Bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Jun 14, 2026
@rok
rok removed the request for review from dangotbanned July 16, 2026 09:57
@rok

rok commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

@paddyroddy 👋

@paddyroddy paddyroddy 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.

Had a scan thought. A lot of the stubs went over my head as I don't know the code base well enough, and hard to see them without the context of the function there too. Have some thoughts anyway.

Nice to see this coming along!

# specific language governing permissions and limitations
# under the License.

"""Type stubs for PyArrow.

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.

Just noting this file was added in #48618

Comment thread .pre-commit-config.yaml
@@ -136,11 +136,22 @@ repos:
- id: flake8

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.

Out of scope, but would suggest we move to ruff at some point. Faster, more frequent updates, and nicer maintainer.

Comment thread python/pyarrow/fs.py
# handle fsspec-compatible filesystems
try:
import fsspec
import fsspec # type: ignore[import-not-found,import-untyped]

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.

Looks like #48618 introduced mypy, pyright, and ty. What about https://github.com/facebook/pyrefly?

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.

I haven't checked, do type: ignore statement codes work across these different type checkers. I've recently switched from mypy to ty and noticed some codes were different. But I have been using ty: ignore rather than type: ignore statements, which might explain things.

Comment on lines +85 to +86
IntoArray = TypeAliasType(
"IntoArray",

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.

Is this "int to array" or "into array"?

from typing import Any, Generic, Literal, Protocol, TypeAlias, overload

import numpy as np
import pandas as pd # type: ignore[import-not-found,import-untyped] # pyright: ignore[reportMissingImports,reportMissingTypeStubs] # noqa: E501

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.

Ah, so this is what I asked about elsewhere. So we're having to do different ignores per library? I've noticed that ty works with both type: ignore and ty: ignore.

def fixed_shape_tensor(
value_type: _ValueT,
shape: Sequence[int],
dim_names: Sequence[str] | None = None,

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.

Went to some talks at EuroPython about the new sentinel built-in. At some point we might want to consider, e.g. sentinel("MISSING"), see this Reddit example.

def type_for_alias(name: str) -> DataType: ...
def schema(
fields: SupportsArrowSchema | _SchemaFieldsInput,
metadata: _KeyValueMetadataInput | KeyValueMetadata = None,

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.

Only just spotted this now, but should we also have | None?

Suggested change
metadata: _KeyValueMetadataInput | KeyValueMetadata = None,
metadata: _KeyValueMetadataInput | KeyValueMetadata | None = None,

) -> Schema: ...
def from_numpy_dtype(dtype: np.dtype[Any] | type | str) -> DataType: ...

__all__ = [

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.

These are usually sorted and are done automatically for me. Looks like that is coming from RUF022.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python][Annotations] Add internal type system stubs (_types, error, _stubs_typing)

6 participants