Skip to content

[Python][Annotations] Use numpy.typing.Array1D where only 1-D arrays are accepted #55889

Backlog

Description

@tadeja

Describe the enhancement requested

Type annotations currently use NDArray[Any] for NumPy inputs, also where 1-D arrays are accepted like with pa.array(...), mask= parameters, and the array-like inputs of pyarrow.compute.

numpy.typing exposes Array1D, which is like NDArray but with the shape fixed to one dimension. Use it where type checkers should reject 2-D inputs (and keep NDArray elsewhere, for example with tensors).

This was suggested by @jorisvandenbossche in #55264 (comment)

numpy.typing.Array1D is not yet available in numpy 2.4.6


It's added with numpy 2.6 version: https://numpy.org/devdocs/reference/typing.html#numpy.typing.Array1D

Note

Blocked until PyArrow drops Python 3.11 (EOL 2027-10) as NumPy 2.6 requires Python ≥3.12.

Component(s)

Python

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions