8000 Add type hinting for numeric.py by johanvergeer · Pull Request #38 · numpy/numpy-stubs · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

Add type hinting for numeric.py #38

Merged
merged 6 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.pytest_cache
__pycache__
numpy_stubs.egg-info/
venv
.idea
3 changes: 3 additions & 0 deletions numpy-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import datetime as dt
from numpy.core._internal import _ctypes
from typing import (
Any,
ByteString,
Container,
Dict,
IO,
Expand Down Expand Up @@ -82,6 +83,8 @@ _DtypeLike = Union[

_NdArraySubClass = TypeVar("_NdArraySubClass", bound=ndarray)

_ArrayLike = TypeVar("_ArrayLike")

class dtype:
names: Optional[Tuple[str, ...]]
def __init__(
Expand Down
111 changes: 111 additions & 0 deletions numpy-stubs/core/numeric.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
from types import ModuleType
from typing import (
Sequence,
Optional,
TypeVar,
Union,
Tuple,
List,
Iterable,
Callable,
Any,
)

from numpy import ndarray, dtype, _ArrayLike, _ShapeLike

_T = TypeVar("_T")

def zeros_like(
a: _ArrayLike,
dtype: Optional[dtype] = ...,
order: str = ...,
subok: bool = ...,
shape: Optional[Union[int, Sequence[int]]] = ...,
) -> ndarray[int]: ...
def ones(
shape: _ShapeLike, dtype: Optional[dtype] = ..., order: str = ...
) -> ndarray[int]: ...
def ones_like(
a: _ArrayLike,
dtype: Optional[dtype] = ...,
order: str = ...,
subok: bool = ...,
shape: Optional[_ShapeLike] = ...,
) -> ndarray[int]: ...
def full(
shape: _ShapeLike, fill_value: _T, dtype: Optional[dtype] = ..., order: str = ...
) -> ndarray[_T]: ...
def full_like(
a: _ArrayLike,
fill_value: _T,
dtype: Optional[dtype] = ...,
order: str = ...,
subok: bool = ...,
shape: Optional[_ShapeLike] = ...,
) -> ndarray[_T]: ...
def count_nonzero(
a: _ArrayLike, axis: Optional[Union[int, Tuple[int], Tuple[int, int]]] = ...
) -> Union[int, ndarray[int]]: ...
def isfortran(a: ndarray) -> bool: ...
def argwhere(a: _ArrayLike) -> ndarray: ...
def flatnonzero(a: _ArrayLike) -> ndarray: ...
def correlate(a: _ArrayLike, v: _ArrayLike, mode: str = ...) -> ndarray: ...
def convolve(a: _ArrayLike, v: _ArrayLike, mode: str = ...) -> ndarray: ...
def outer(a: _ArrayLike, b: _ArrayLike, out: ndarray = ...) -> ndarray: ...
def tensordot(
a: _ArrayLike,
b: _ArrayLike,
axes: Union[
int, Tuple[int, int], Tuple[Tuple[int, int], ...], Tuple[List[int, int], ...]
] = ...,
) -> ndarray: ...
def roll(
a: _ArrayLike,
shift: Union[int, Tuple[int, ...]],
axis: Optional[Union[int, Tuple[int, ...]]] = ...,
) -> _T: ...
def rollaxis(a: _ArrayLike, axis: int, start: int = ...) -> ndarray: ...
def normalize_axis_tuple(
axis: Union[int, Iterable[int]],
ndim: int,
argname: Optional[str] = ...,
allow_duplicate: bool = ...,
) -> Tuple[int, ...]: ...
def moveaxis(
a: ndarray,
source: Union[int, Sequence[int]],
destination: Union[int, Sequence[int]],
) -> ndarray: ...
def cross(
a: _ArrayLike,
b: _ArrayLike,
axisa: int = ...,
axisb: int = ...,
axisc: int = ...,
axis: Optional[int] = ...,
) -> ndarray: ...
def indices(
dimensions: Sequence[int], dtype: dtype = ..., sparse: bool = ...
) -> Union[ndarray, Tuple[ndarray, ...]]: ...
def fromfunction(function: Callable, shape: Tuple[int, int], **kwargs) -> Any: ...
def isscalar(element: Any) -> bool: ...
def binary_repr(num: int, width: Optional[int] = ...) -> str: ...
def base_repr(number: int, base: int = ..., padding: int = ...) -> str: ...
def identity(n: int, dtype: Optional[dtype] = ...) -> ndarray: ...
def allclose(
a: _ArrayLike,
b: _ArrayLike,
rtol: float = ...,
atol: float = ...,
equal_nan: bool = ...,
) -> bool: ...
def isclose(
a: _ArrayLike,
b: _ArrayLike,
rtol: float = ...,
atol: float = ...,
equal_nan: bool = ...,
) -> _ArrayLike: ...
def array_equal(a1: _ArrayLike, a2: _ArrayLike) -> bool: ...
def array_equiv(a1: _ArrayLike, a2: _ArrayLike) -> bool: ...
def extend_all(module: ModuleType): ...
20 changes: 20 additions & 0 deletions numpy-stubs/core/numerictypes.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Any, Optional, Union, Tuple, List

from numpy import dtype

def maximum_sctype(t: dtype) -> dtype: ...
def issctype(rep: Any) -> bool: ...
def obj2sctype(rep: Any, default: Optional[Any] = ...) -> type: ...
def issubclass_(
arg1: type, arg2: Union[type, Tuple[Union[type, Tuple], ...]]
) -> bool: ...
def issubsctype(
arg1: type, arg2: Union[type, Tuple[Union[type, Tuple], ...]]
) -> bool: ...
def issubdtype(
arg1: Union[object, type], arg2: Union[type, Tuple[Union[type, Tuple], ...]]
) -> bool: ...
def sctype2char(sctype: Any) -> str: ...
def find_common_type(
array_types: Union[dtype, List[dtype]], scalar_types: Union[dtype, List[dtype]]
) -> dtype: ...
0