data-science-types icon indicating copy to clipboard operation
data-science-types copied to clipboard

bug in ndarray: incompatible type error

Open sfolje0 opened this issue 5 years ago • 1 comments

I think there is a bug in ndarray type hint. I think that in case of np.array that has one row with only integers (type int or int[64]) and one row with at least one float (e.g. type float), then it produces an error since rows have different types so conflict like "np.ndarray[float] != np.ndarray[int]" occurs.

Reproducing code example:

# bug.py
import numpy as np 
arr = np.array([[4.2, 2, 3.5], [12, 3, 6]])   

and run mypy:

$ mypy bug.py 

Error message:

bug.py:3: error: Argument 1 to "array" has incompatible type "List[object]"; expected "Union[List[bool], List[List[bool]], List[List[List[bool]]], List[List[List[List[bool]]]]]"

NumPy/Python/data-science-types versions information:

1.19.2 / 3.8.5 / 0.2.20

sfolje0 avatar Nov 23 '20 21:11 sfolje0

Yeah, that's a bug. I'm not sure we can fix it. Maybe we could use List[Union[int, float]].

tmke8 avatar Nov 23 '20 21:11 tmke8