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

Missing Union with primitive (_DType) types in numpy functions

Open pbnoxious opened this issue 5 years ago • 0 comments

Many numpy functions allow the usage not only of an _ArrayLike (List or ndarray) argument but also simple primitive value. This is currently often not allowed with the type hints.

Two examples of code that results in errors when checked with mypy:

  • myarr = np.array(1.0) -> No overload variant of "array" matches argument type "float"
  • np.append(myarr, 1.0) -> Argument 2 to "append" has incompatible type "float"; expected "Union[Array[Any], Sequence[Any]]"

This could be fixed by using a Union[_ArrayLike, _DType] instead of just _ArrayLike. Because this might be done for a lot of functions, I have refrained from partially changing the code where I know numpy accepts primitive types and submitting a pull request. I think this is better implemented on a general scale with more overview than I currently have.

pbnoxious avatar Aug 21 '20 09:08 pbnoxious