Skip to content

[Python][Annotations] Consider narrowing return types in pyarrow-stubs with generic private base classes #55767

Done

Description

@tadeja

Describe the enhancement requested

#55264 (issue #55263, under umbrella issue #32609) intentionally avoids generics to keep the first stage simpler. As a result, some methods inherited from private base classes return unions on every subclass:

  1. _PandasConvertible.to_pandas() in python/pyarrow-stubs/__lib/array.pyi returns pd.Series | pd.DataFrame for arrays and tables (post-GH-55263: [Python][Annotations] Add internal types and core data structures #55264)
    Consider making _PandasConvertible generic over its return type to narrow it without duplicated signatures or per-class overloads.

  2. _Tabular column access in python/pyarrow-stubs/__lib/table.pyi
    (__getitem__, column, columns, itercolumns) returns Array | ChunkedArray variants on both RecordBatch and Table.
    Consider a _Tabular[_ColumnT] with _ColumnT = TypeVar("_ColumnT", Array, ChunkedArray) to narrow these.

  3. Review the rest of python/pyarrow-stubs/ for similar private base classes where an internal Generic[...] would narrow inherited return types.

Note: public classes preferably remain non-generic.
Also consider adding assert_type tests in python/pyarrow-stubs-tests/

Component(s)

Python

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions