diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2020-09-07 11:04:05 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-07 11:04:05 -0600 |
commit | 16821b94e973196a5d335ad2c2a059c48d953a1e (patch) | |
tree | 023f466c2c5e1e1992f45b968b246d9ab3181113 /numpy/tests | |
parent | 1cb5f15109f0f8eb03afd662bc7c85dd6d10313a (diff) | |
parent | d15254d487fa432b3f14aa32c9e9552835f76248 (diff) | |
download | numpy-16821b94e973196a5d335ad2c2a059c48d953a1e.tar.gz |
Merge branch 'master' into ndarray-methods
Diffstat (limited to 'numpy/tests')
-rw-r--r-- | numpy/tests/test_typing.py | 2 | ||||
-rw-r--r-- | numpy/tests/typing/fail/linspace.py | 13 | ||||
-rw-r--r-- | numpy/tests/typing/fail/modules.py | 3 | ||||
-rw-r--r-- | numpy/tests/typing/fail/scalars.py | 11 | ||||
-rw-r--r-- | numpy/tests/typing/pass/linspace.py | 22 | ||||
-rw-r--r-- | numpy/tests/typing/pass/scalars.py | 37 | ||||
-rw-r--r-- | numpy/tests/typing/reveal/linspace.py | 6 | ||||
-rw-r--r-- | numpy/tests/typing/reveal/modules.py | 20 |
8 files changed, 107 insertions, 7 deletions
diff --git a/numpy/tests/test_typing.py b/numpy/tests/test_typing.py index 04ea3c64d..32342d321 100644 --- a/numpy/tests/test_typing.py +++ b/numpy/tests/test_typing.py @@ -89,7 +89,7 @@ def test_fail(path): for i, line in enumerate(lines): lineno = i + 1 - if " E:" not in line and lineno not in errors: + if line.startswith('#') or (" E:" not in line and lineno not in errors): continue target_line = lines[lineno - 1] diff --git a/numpy/tests/typing/fail/linspace.py b/numpy/tests/typing/fail/linspace.py new file mode 100644 index 000000000..a9769c5d6 --- /dev/null +++ b/numpy/tests/typing/fail/linspace.py @@ -0,0 +1,13 @@ +import numpy as np + +np.linspace(None, 'bob') # E: No overload variant +np.linspace(0, 2, num=10.0) # E: No overload variant +np.linspace(0, 2, endpoint='True') # E: No overload variant +np.linspace(0, 2, retstep=b'False') # E: No overload variant +np.linspace(0, 2, dtype=0) # E: No overload variant +np.linspace(0, 2, axis=None) # E: No overload variant + +np.logspace(None, 'bob') # E: Argument 1 +np.logspace(0, 2, base=None) # E: Argument "base" + +np.geomspace(None, 'bob') # E: Argument 1 diff --git a/numpy/tests/typing/fail/modules.py b/numpy/tests/typing/fail/modules.py new file mode 100644 index 000000000..e7ffe8920 --- /dev/null +++ b/numpy/tests/typing/fail/modules.py @@ -0,0 +1,3 @@ +import numpy as np + +np.testing.bob # E: Module has no attribute diff --git a/numpy/tests/typing/fail/scalars.py b/numpy/tests/typing/fail/scalars.py index 5d7221895..47c031163 100644 --- a/numpy/tests/typing/fail/scalars.py +++ b/numpy/tests/typing/fail/scalars.py @@ -32,11 +32,16 @@ dt_64 = np.datetime64(0, "D") td_64 = np.timedelta64(1, "h") dt_64 + dt_64 # E: Unsupported operand types - td_64 - dt_64 # E: Unsupported operand types -td_64 / dt_64 # E: No overload td_64 % 1 # E: Unsupported operand types -td_64 % dt_64 # E: Unsupported operand types + +# NOTE: The 2 tests below currently don't work due to the broad +# (i.e. untyped) signature of `generic.__truediv__()` and `.__mod__()`. +# TODO: Revisit this once annotations are added to the +# `_ArrayOrScalarCommon` magic methods. + +# td_64 / dt_64 # E: No overload +# td_64 % dt_64 # E: Unsupported operand types class A: diff --git a/numpy/tests/typing/pass/linspace.py b/numpy/tests/typing/pass/linspace.py new file mode 100644 index 000000000..8c6d0d56b --- /dev/null +++ b/numpy/tests/typing/pass/linspace.py @@ -0,0 +1,22 @@ +import numpy as np + +class Index: + def __index__(self) -> int: + return 0 + +np.linspace(0, 2) +np.linspace(0.5, [0, 1, 2]) +np.linspace([0, 1, 2], 3) +np.linspace(0j, 2) +np.linspace(0, 2, num=10) +np.linspace(0, 2, endpoint=True) +np.linspace(0, 2, retstep=True) +np.linspace(0j, 2j, retstep=True) +np.linspace(0, 2, dtype=bool) +np.linspace([0, 1], [2, 3], axis=Index()) + +np.logspace(0, 2, base=2) +np.logspace(0, 2, base=2) +np.logspace(0, 2, base=[1j, 2j], num=2) + +np.geomspace(1, 2) diff --git a/numpy/tests/typing/pass/scalars.py b/numpy/tests/typing/pass/scalars.py index 1c7ace282..c02e1ed36 100644 --- a/numpy/tests/typing/pass/scalars.py +++ b/numpy/tests/typing/pass/scalars.py @@ -1,27 +1,38 @@ +import sys +import datetime as dt + import numpy as np # Construction +class D: + def __index__(self) -> int: + return 0 + + class C: - def __complex__(self): + def __complex__(self) -> complex: return 3j class B: - def __int__(self): + def __int__(self) -> int: return 4 class A: - def __float__(self): + def __float__(self) -> float: return 4.0 np.complex64(3j) +np.complex64(A()) np.complex64(C()) np.complex128(3j) np.complex128(C()) np.complex128(None) +np.complex64("1.2") +np.complex128(b"2j") np.int8(4) np.int16(3.4) @@ -29,11 +40,20 @@ np.int32(4) np.int64(-1) np.uint8(B()) np.uint32() +np.int32("1") +np.int64(b"2") np.float16(A()) np.float32(16) np.float64(3.0) np.float64(None) +np.float32("1") +np.float16(b"2.5") + +if sys.version_info >= (3, 8): + np.uint64(D()) + np.float32(D()) + np.complex64(D()) np.bytes_(b"hello") np.bytes_("hello", 'utf-8') @@ -66,14 +86,25 @@ np.uint64().shape # Time structures np.datetime64() np.datetime64(0, "D") +np.datetime64(0, b"D") +np.datetime64(0, ('ms', 3)) np.datetime64("2019") +np.datetime64(b"2019") np.datetime64("2019", "D") +np.datetime64(np.datetime64()) +np.datetime64(dt.datetime(2000, 5, 3)) np.datetime64(None) np.datetime64(None, "D") np.timedelta64() np.timedelta64(0) np.timedelta64(0, "D") +np.timedelta64(0, ('ms', 3)) +np.timedelta64(0, b"D") +np.timedelta64("3") +np.timedelta64(b"5") +np.timedelta64(np.timedelta64(2)) +np.timedelta64(dt.timedelta(2)) np.timedelta64(None) np.timedelta64(None, "D") diff --git a/numpy/tests/typing/reveal/linspace.py b/numpy/tests/typing/reveal/linspace.py new file mode 100644 index 000000000..cfbbdf390 --- /dev/null +++ b/numpy/tests/typing/reveal/linspace.py @@ -0,0 +1,6 @@ +import numpy as np + +reveal_type(np.linspace(0, 10)) # E: numpy.ndarray +reveal_type(np.linspace(0, 10, retstep=True)) # E: Tuple[numpy.ndarray, numpy.inexact] +reveal_type(np.logspace(0, 10)) # E: numpy.ndarray +reveal_type(np.geomspace(1, 10)) # E: numpy.ndarray diff --git a/numpy/tests/typing/reveal/modules.py b/numpy/tests/typing/reveal/modules.py new file mode 100644 index 000000000..406463152 --- /dev/null +++ b/numpy/tests/typing/reveal/modules.py @@ -0,0 +1,20 @@ +import numpy as np + +reveal_type(np) # E: ModuleType + +reveal_type(np.char) # E: ModuleType +reveal_type(np.ctypeslib) # E: ModuleType +reveal_type(np.emath) # E: ModuleType +reveal_type(np.fft) # E: ModuleType +reveal_type(np.lib) # E: ModuleType +reveal_type(np.linalg) # E: ModuleType +reveal_type(np.ma) # E: ModuleType +reveal_type(np.matrixlib) # E: ModuleType +reveal_type(np.polynomial) # E: ModuleType +reveal_type(np.random) # E: ModuleType +reveal_type(np.rec) # E: ModuleType +reveal_type(np.testing) # E: ModuleType +reveal_type(np.version) # E: ModuleType + +# TODO: Remove when annotations have been added to `np.testing.assert_equal` +reveal_type(np.testing.assert_equal) # E: Any |