Skip to content

TYP: Numpy compatibility of definition of "array like" #41807

Open
@Dr-Irv

Description

@Dr-Irv

In pandas/_typing.py, we define ArrayLike as:

ArrayLike = Union["ExtensionArray", np.ndarray]

In the numpy glossary https://numpy.org/doc/stable/glossary.html?highlight=array_like, numpy defines array_like as:

Any scalar or sequence that can be interpreted as an ndarray. In addition to ndarrays and scalars this category includes lists (possibly nested and with different element types) and tuples. Any argument accepted by numpy.array is array_like.

Are we creating confusion by using the term ArrayLike to only mean arrays, whereas numpy defines it to include scalars?

This came up in terms of reconciling the arguments of np.searchsorted() and ExtensionArray.searchsorted().

Comments from @jbrockmendel and @simonjayhawkins welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExtensionArrayExtending pandas with custom dtypes or arrays.Typingtype annotations, mypy/pyright type checking

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions