From 7ec24901336ef21323f3d0fdfb0c3854b22a05b6 Mon Sep 17 00:00:00 2001 From: Grier Phillips Date: Thu, 9 Nov 2017 10:12:03 -0700 Subject: [PATCH 1/2] Add arange method Added the arange method to the array creation routines. np.arange requires a number (Union[int, float]) for the start, stop, and step parameters and returns an ndarray[int, float]. --- numpy-mypy/numpy/__init__.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/numpy-mypy/numpy/__init__.pyi b/numpy-mypy/numpy/__init__.pyi index 7da3778..0b8a6b0 100644 --- a/numpy-mypy/numpy/__init__.pyi +++ b/numpy-mypy/numpy/__init__.pyi @@ -441,6 +441,9 @@ class ndarray(_ArrayLike[_S], Generic[_S]): def array(object: Any, dtype: Any=None, copy: bool=True, order: str=None, subok: bool=False, ndmin: int=0) -> ndarray[Any]: ... +def arange(start: Union[int, float]=None, stop: Union[int, float], + step: Union[int, flaot]=None, + dtype: DtypeType=None) -> ndarray[Union[int, float]]: ... def asarray(a: Any, dtype: DtypeType=None, order: str=None) -> ndarray[Any]: ... def asanyarray(a: Any, dtype: DtypeType=None, order: str=None) -> ndarray[Any]: ... # TODO figure out a way to restrict the return type def asmatrix(data: Any, dtype: DtypeType=None) -> Any: ... # TODO define matrix From 007d0b8719ad4f67b6558e5ce7ffc569578a539d Mon Sep 17 00:00:00 2001 From: Grier Phillips Date: Thu, 9 Nov 2017 11:16:17 -0700 Subject: [PATCH 2/2] Fix argument structure Given the argument structure of `arange([start], stop, [step, dtype])` mypy breaks and is unable to parse files after trying to import numpy typestubs. To fix this issue stop is defaulted to None. Also fixed a typo in step (flaot to float). --- numpy-mypy/numpy/__init__.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numpy-mypy/numpy/__init__.pyi b/numpy-mypy/numpy/__init__.pyi index 0b8a6b0..5a716e0 100644 --- a/numpy-mypy/numpy/__init__.pyi +++ b/numpy-mypy/numpy/__init__.pyi @@ -441,8 +441,8 @@ class ndarray(_ArrayLike[_S], Generic[_S]): def array(object: Any, dtype: Any=None, copy: bool=True, order: str=None, subok: bool=False, ndmin: int=0) -> ndarray[Any]: ... -def arange(start: Union[int, float]=None, stop: Union[int, float], - step: Union[int, flaot]=None, +def arange(start: Union[int, float]=None, stop: Union[int, float]=None, + step: Union[int, float]=None, dtype: DtypeType=None) -> ndarray[Union[int, float]]: ... def asarray(a: Any, dtype: DtypeType=None, order: str=None) -> ndarray[Any]: ... def asanyarray(a: Any, dtype: DtypeType=None, order: str=None) -> ndarray[Any]: ... # TODO figure out a way to restrict the return type