Skip to content

BUG: Incorrect typing of return values of numpy.vectorize #20856

@WKuipers

Description

@WKuipers

Describe the issue:

In https://github.com/numpy/numpy/blob/main/numpy/__init__.pyi#L3692 the return type of call of a vectorized function is defined to always be NDArray[Any], but this is not the case in practice.

As mentioned in the documentation (https://numpy.org/doc/stable/reference/generated/numpy.vectorize.html):

... and returns a single numpy array or a tuple of numpy arrays.

Reproduce the code example:

a = np.array([[1.0, 2.0], [3.0, 4.0]])
def returns_tuple(a):
     return (a, a)
b: Tuple[np.ndarray] = np.vectorize(returns_tuple)(a)

Error message:

Incompatible types in assignment (expression has type "ndarray[Any, dtype[Any]]", variable has type "Tuple[ndarray[Any, Any]]")

NumPy/Python version information:

1.22.1 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions