Skip to content

TYP: Wrong type hint for interp #27811

@NoureldinYosri

Description

@NoureldinYosri

Describe the issue:

The type hints for interp assert that the return dtype is a numpy array, but when the function is called with a scaler it gives a float. This raises some mypy errors.

@overload
def interp(
x: _ArrayLikeFloat_co,
xp: _ArrayLikeFloat_co,
fp: _ArrayLikeFloat_co,
left: None | _FloatLike_co = ...,
right: None | _FloatLike_co = ...,
period: None | _FloatLike_co = ...,
) -> NDArray[float64]: ...
@overload
def interp(
x: _ArrayLikeFloat_co,
xp: _ArrayLikeFloat_co,
fp: _ArrayLikeComplex_co,
left: None | _ComplexLike_co = ...,
right: None | _ComplexLike_co = ...,
period: None | _FloatLike_co = ...,
) -> NDArray[complex128]: ...

Reproduce the code example:

>>> np.interp(0, [1, 2], [3, 4])
np.float64(3.0)

Error message:

my_code.py::123 error: Incompatible return value type (got "ndarray[Any, Any]", expected "float")  [return-value]

Python and NumPy Versions:

python: 3.12.2
numpy: 2.1.3

Runtime Environment:

No response

Context for the issue:

No response

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