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

Commit be9a479

Browse files
szb0shoyer
authored andcommitted
Array Creation Routines: zeros and ones (#33)
* add functions for zeros and ones too few args formatting new line * black linting
1 parent ad402db commit be9a479

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

numpy-stubs/__init__.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,12 @@ def array(
479479
subok: bool = ...,
480480
ndmin: int = ...,
481481
) -> ndarray: ...
482+
def zeros(
483+
shape: _ShapeLike, dtype: _DtypeLike = ..., order: Optional[str] = ...
484+
) -> ndarray: ...
485+
def ones(
486+
shape: _ShapeLike, dtype: _DtypeLike = ..., order: Optional[str] = ...
487+
) -> ndarray: ...
482488

483489
# TODO(shoyer): remove when the full numpy namespace is defined
484490
def __getattr__(name: str) -> Any: ...

tests/fail/simple.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""Simple expression that should fail with mypy."""
2+
3+
import numpy as np
4+
5+
# Array creation routines checks
6+
np.zeros("test") # E: incompatible type
7+
np.zeros() # E: Too few arguments
8+
9+
np.ones("test") # E: incompatible type
10+
np.ones() # E: Too few arguments

tests/pass/simple.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def ndarray_func(x):
1313
array == 1
1414
array.dtype == float
1515

16+
# Array creation routines checks
17+
ndarray_func(np.zeros([1, 2]))
18+
ndarray_func(np.ones([1, 2]))
19+
1620
# Dtype construction
1721
np.dtype(float)
1822
np.dtype(np.float64)

0 commit comments

Comments
 (0)