numpy errors #1206
Replies: 4 comments 1 reply
-
Can you provide an actual fully self-contained example? |
Beta Was this translation helpful? Give feedback.
-
Sure:
|
Beta Was this translation helpful? Give feedback.
-
This explains a lot. The error is correct in this case, what you'd want here is to either call the |
Beta Was this translation helpful? Give feedback.
-
If the array type is known (eg. int, float) then use np.ndarray as the annotation instead of npt.ArrayLike - is that correct? |
Beta Was this translation helpful? Give feedback.
-
The mypy.ini file includes:
plugins = numpy.typing.mypy_plugin
On python+numpy code, mypy throws errors of the form:
error: Incompatible types in assignment (expression has type "Union[Any, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]", variable has type "int")
For example, the line:
indices: np.ndarray = this_vector.nonzero()[0]
causes the above error. If changed to a list:
indices: list[float] = this_vector.nonzero()[0].tolist()
it works but defeats the purpose of using numpy which performers faster and the code is cleaner.
Please explain what is going on. Thanks
Beta Was this translation helpful? Give feedback.
All reactions