Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .venv/lib/python3.11/site-packages/numpy/doc/__init__.py +26 -0
- .venv/lib/python3.11/site-packages/numpy/doc/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/doc/__pycache__/constants.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/doc/__pycache__/ufuncs.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/doc/constants.py +412 -0
- .venv/lib/python3.11/site-packages/numpy/doc/ufuncs.py +137 -0
- .venv/lib/python3.11/site-packages/numpy/linalg/tests/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/typing/__init__.py +175 -0
- .venv/lib/python3.11/site-packages/numpy/typing/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/typing/__pycache__/mypy_plugin.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/typing/__pycache__/setup.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/numpy/typing/mypy_plugin.py +196 -0
- .venv/lib/python3.11/site-packages/numpy/typing/setup.py +11 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/__init__.py +0 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/arithmetic.pyi +121 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/array_constructors.pyi +33 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/array_like.pyi +16 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/array_pad.pyi +6 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/arrayprint.pyi +14 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/arrayterator.pyi +14 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/bitwise_ops.pyi +20 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/char.pyi +66 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/chararray.pyi +62 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/comparisons.pyi +27 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/constants.pyi +7 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/datasource.pyi +15 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/dtype.pyi +20 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/einsumfunc.pyi +12 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/false_positives.pyi +11 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/flatiter.pyi +25 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/fromnumeric.pyi +161 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/histograms.pyi +12 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/index_tricks.pyi +14 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/lib_function_base.pyi +53 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/lib_polynomial.pyi +29 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/lib_utils.pyi +13 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/lib_version.pyi +6 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/linalg.pyi +48 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/memmap.pyi +5 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/modules.pyi +18 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/multiarray.pyi +55 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/ndarray.pyi +11 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/ndarray_misc.pyi +43 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/nditer.pyi +8 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/nested_sequence.pyi +17 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/npyio.pyi +27 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/numerictypes.pyi +11 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/random.pyi +61 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/rec.pyi +17 -0
- .venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/scalars.pyi +92 -0
.venv/lib/python3.11/site-packages/numpy/doc/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
ref_dir = os.path.join(os.path.dirname(__file__))
|
| 4 |
+
|
| 5 |
+
__all__ = sorted(f[:-3] for f in os.listdir(ref_dir) if f.endswith('.py') and
|
| 6 |
+
not f.startswith('__'))
|
| 7 |
+
|
| 8 |
+
for f in __all__:
|
| 9 |
+
__import__(__name__ + '.' + f)
|
| 10 |
+
|
| 11 |
+
del f, ref_dir
|
| 12 |
+
|
| 13 |
+
__doc__ = """\
|
| 14 |
+
Topical documentation
|
| 15 |
+
=====================
|
| 16 |
+
|
| 17 |
+
The following topics are available:
|
| 18 |
+
%s
|
| 19 |
+
|
| 20 |
+
You can view them by
|
| 21 |
+
|
| 22 |
+
>>> help(np.doc.TOPIC) #doctest: +SKIP
|
| 23 |
+
|
| 24 |
+
""" % '\n- '.join([''] + __all__)
|
| 25 |
+
|
| 26 |
+
__all__.extend(['__doc__'])
|
.venv/lib/python3.11/site-packages/numpy/doc/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (1.37 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/doc/__pycache__/constants.cpython-311.pyc
ADDED
|
Binary file (9.54 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/doc/__pycache__/ufuncs.cpython-311.pyc
ADDED
|
Binary file (5.56 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/doc/constants.py
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
=========
|
| 3 |
+
Constants
|
| 4 |
+
=========
|
| 5 |
+
|
| 6 |
+
.. currentmodule:: numpy
|
| 7 |
+
|
| 8 |
+
NumPy includes several constants:
|
| 9 |
+
|
| 10 |
+
%(constant_list)s
|
| 11 |
+
"""
|
| 12 |
+
#
|
| 13 |
+
# Note: the docstring is autogenerated.
|
| 14 |
+
#
|
| 15 |
+
import re
|
| 16 |
+
import textwrap
|
| 17 |
+
|
| 18 |
+
# Maintain same format as in numpy.add_newdocs
|
| 19 |
+
constants = []
|
| 20 |
+
def add_newdoc(module, name, doc):
|
| 21 |
+
constants.append((name, doc))
|
| 22 |
+
|
| 23 |
+
add_newdoc('numpy', 'pi',
|
| 24 |
+
"""
|
| 25 |
+
``pi = 3.1415926535897932384626433...``
|
| 26 |
+
|
| 27 |
+
References
|
| 28 |
+
----------
|
| 29 |
+
https://en.wikipedia.org/wiki/Pi
|
| 30 |
+
|
| 31 |
+
""")
|
| 32 |
+
|
| 33 |
+
add_newdoc('numpy', 'e',
|
| 34 |
+
"""
|
| 35 |
+
Euler's constant, base of natural logarithms, Napier's constant.
|
| 36 |
+
|
| 37 |
+
``e = 2.71828182845904523536028747135266249775724709369995...``
|
| 38 |
+
|
| 39 |
+
See Also
|
| 40 |
+
--------
|
| 41 |
+
exp : Exponential function
|
| 42 |
+
log : Natural logarithm
|
| 43 |
+
|
| 44 |
+
References
|
| 45 |
+
----------
|
| 46 |
+
https://en.wikipedia.org/wiki/E_%28mathematical_constant%29
|
| 47 |
+
|
| 48 |
+
""")
|
| 49 |
+
|
| 50 |
+
add_newdoc('numpy', 'euler_gamma',
|
| 51 |
+
"""
|
| 52 |
+
``γ = 0.5772156649015328606065120900824024310421...``
|
| 53 |
+
|
| 54 |
+
References
|
| 55 |
+
----------
|
| 56 |
+
https://en.wikipedia.org/wiki/Euler-Mascheroni_constant
|
| 57 |
+
|
| 58 |
+
""")
|
| 59 |
+
|
| 60 |
+
add_newdoc('numpy', 'inf',
|
| 61 |
+
"""
|
| 62 |
+
IEEE 754 floating point representation of (positive) infinity.
|
| 63 |
+
|
| 64 |
+
Returns
|
| 65 |
+
-------
|
| 66 |
+
y : float
|
| 67 |
+
A floating point representation of positive infinity.
|
| 68 |
+
|
| 69 |
+
See Also
|
| 70 |
+
--------
|
| 71 |
+
isinf : Shows which elements are positive or negative infinity
|
| 72 |
+
|
| 73 |
+
isposinf : Shows which elements are positive infinity
|
| 74 |
+
|
| 75 |
+
isneginf : Shows which elements are negative infinity
|
| 76 |
+
|
| 77 |
+
isnan : Shows which elements are Not a Number
|
| 78 |
+
|
| 79 |
+
isfinite : Shows which elements are finite (not one of Not a Number,
|
| 80 |
+
positive infinity and negative infinity)
|
| 81 |
+
|
| 82 |
+
Notes
|
| 83 |
+
-----
|
| 84 |
+
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic
|
| 85 |
+
(IEEE 754). This means that Not a Number is not equivalent to infinity.
|
| 86 |
+
Also that positive infinity is not equivalent to negative infinity. But
|
| 87 |
+
infinity is equivalent to positive infinity.
|
| 88 |
+
|
| 89 |
+
`Inf`, `Infinity`, `PINF` and `infty` are aliases for `inf`.
|
| 90 |
+
|
| 91 |
+
Examples
|
| 92 |
+
--------
|
| 93 |
+
>>> np.inf
|
| 94 |
+
inf
|
| 95 |
+
>>> np.array([1]) / 0.
|
| 96 |
+
array([ Inf])
|
| 97 |
+
|
| 98 |
+
""")
|
| 99 |
+
|
| 100 |
+
add_newdoc('numpy', 'nan',
|
| 101 |
+
"""
|
| 102 |
+
IEEE 754 floating point representation of Not a Number (NaN).
|
| 103 |
+
|
| 104 |
+
Returns
|
| 105 |
+
-------
|
| 106 |
+
y : A floating point representation of Not a Number.
|
| 107 |
+
|
| 108 |
+
See Also
|
| 109 |
+
--------
|
| 110 |
+
isnan : Shows which elements are Not a Number.
|
| 111 |
+
|
| 112 |
+
isfinite : Shows which elements are finite (not one of
|
| 113 |
+
Not a Number, positive infinity and negative infinity)
|
| 114 |
+
|
| 115 |
+
Notes
|
| 116 |
+
-----
|
| 117 |
+
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic
|
| 118 |
+
(IEEE 754). This means that Not a Number is not equivalent to infinity.
|
| 119 |
+
|
| 120 |
+
`NaN` and `NAN` are aliases of `nan`.
|
| 121 |
+
|
| 122 |
+
Examples
|
| 123 |
+
--------
|
| 124 |
+
>>> np.nan
|
| 125 |
+
nan
|
| 126 |
+
>>> np.log(-1)
|
| 127 |
+
nan
|
| 128 |
+
>>> np.log([-1, 1, 2])
|
| 129 |
+
array([ NaN, 0. , 0.69314718])
|
| 130 |
+
|
| 131 |
+
""")
|
| 132 |
+
|
| 133 |
+
add_newdoc('numpy', 'newaxis',
|
| 134 |
+
"""
|
| 135 |
+
A convenient alias for None, useful for indexing arrays.
|
| 136 |
+
|
| 137 |
+
Examples
|
| 138 |
+
--------
|
| 139 |
+
>>> newaxis is None
|
| 140 |
+
True
|
| 141 |
+
>>> x = np.arange(3)
|
| 142 |
+
>>> x
|
| 143 |
+
array([0, 1, 2])
|
| 144 |
+
>>> x[:, newaxis]
|
| 145 |
+
array([[0],
|
| 146 |
+
[1],
|
| 147 |
+
[2]])
|
| 148 |
+
>>> x[:, newaxis, newaxis]
|
| 149 |
+
array([[[0]],
|
| 150 |
+
[[1]],
|
| 151 |
+
[[2]]])
|
| 152 |
+
>>> x[:, newaxis] * x
|
| 153 |
+
array([[0, 0, 0],
|
| 154 |
+
[0, 1, 2],
|
| 155 |
+
[0, 2, 4]])
|
| 156 |
+
|
| 157 |
+
Outer product, same as ``outer(x, y)``:
|
| 158 |
+
|
| 159 |
+
>>> y = np.arange(3, 6)
|
| 160 |
+
>>> x[:, newaxis] * y
|
| 161 |
+
array([[ 0, 0, 0],
|
| 162 |
+
[ 3, 4, 5],
|
| 163 |
+
[ 6, 8, 10]])
|
| 164 |
+
|
| 165 |
+
``x[newaxis, :]`` is equivalent to ``x[newaxis]`` and ``x[None]``:
|
| 166 |
+
|
| 167 |
+
>>> x[newaxis, :].shape
|
| 168 |
+
(1, 3)
|
| 169 |
+
>>> x[newaxis].shape
|
| 170 |
+
(1, 3)
|
| 171 |
+
>>> x[None].shape
|
| 172 |
+
(1, 3)
|
| 173 |
+
>>> x[:, newaxis].shape
|
| 174 |
+
(3, 1)
|
| 175 |
+
|
| 176 |
+
""")
|
| 177 |
+
|
| 178 |
+
add_newdoc('numpy', 'NZERO',
|
| 179 |
+
"""
|
| 180 |
+
IEEE 754 floating point representation of negative zero.
|
| 181 |
+
|
| 182 |
+
Returns
|
| 183 |
+
-------
|
| 184 |
+
y : float
|
| 185 |
+
A floating point representation of negative zero.
|
| 186 |
+
|
| 187 |
+
See Also
|
| 188 |
+
--------
|
| 189 |
+
PZERO : Defines positive zero.
|
| 190 |
+
|
| 191 |
+
isinf : Shows which elements are positive or negative infinity.
|
| 192 |
+
|
| 193 |
+
isposinf : Shows which elements are positive infinity.
|
| 194 |
+
|
| 195 |
+
isneginf : Shows which elements are negative infinity.
|
| 196 |
+
|
| 197 |
+
isnan : Shows which elements are Not a Number.
|
| 198 |
+
|
| 199 |
+
isfinite : Shows which elements are finite - not one of
|
| 200 |
+
Not a Number, positive infinity and negative infinity.
|
| 201 |
+
|
| 202 |
+
Notes
|
| 203 |
+
-----
|
| 204 |
+
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic
|
| 205 |
+
(IEEE 754). Negative zero is considered to be a finite number.
|
| 206 |
+
|
| 207 |
+
Examples
|
| 208 |
+
--------
|
| 209 |
+
>>> np.NZERO
|
| 210 |
+
-0.0
|
| 211 |
+
>>> np.PZERO
|
| 212 |
+
0.0
|
| 213 |
+
|
| 214 |
+
>>> np.isfinite([np.NZERO])
|
| 215 |
+
array([ True])
|
| 216 |
+
>>> np.isnan([np.NZERO])
|
| 217 |
+
array([False])
|
| 218 |
+
>>> np.isinf([np.NZERO])
|
| 219 |
+
array([False])
|
| 220 |
+
|
| 221 |
+
""")
|
| 222 |
+
|
| 223 |
+
add_newdoc('numpy', 'PZERO',
|
| 224 |
+
"""
|
| 225 |
+
IEEE 754 floating point representation of positive zero.
|
| 226 |
+
|
| 227 |
+
Returns
|
| 228 |
+
-------
|
| 229 |
+
y : float
|
| 230 |
+
A floating point representation of positive zero.
|
| 231 |
+
|
| 232 |
+
See Also
|
| 233 |
+
--------
|
| 234 |
+
NZERO : Defines negative zero.
|
| 235 |
+
|
| 236 |
+
isinf : Shows which elements are positive or negative infinity.
|
| 237 |
+
|
| 238 |
+
isposinf : Shows which elements are positive infinity.
|
| 239 |
+
|
| 240 |
+
isneginf : Shows which elements are negative infinity.
|
| 241 |
+
|
| 242 |
+
isnan : Shows which elements are Not a Number.
|
| 243 |
+
|
| 244 |
+
isfinite : Shows which elements are finite - not one of
|
| 245 |
+
Not a Number, positive infinity and negative infinity.
|
| 246 |
+
|
| 247 |
+
Notes
|
| 248 |
+
-----
|
| 249 |
+
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic
|
| 250 |
+
(IEEE 754). Positive zero is considered to be a finite number.
|
| 251 |
+
|
| 252 |
+
Examples
|
| 253 |
+
--------
|
| 254 |
+
>>> np.PZERO
|
| 255 |
+
0.0
|
| 256 |
+
>>> np.NZERO
|
| 257 |
+
-0.0
|
| 258 |
+
|
| 259 |
+
>>> np.isfinite([np.PZERO])
|
| 260 |
+
array([ True])
|
| 261 |
+
>>> np.isnan([np.PZERO])
|
| 262 |
+
array([False])
|
| 263 |
+
>>> np.isinf([np.PZERO])
|
| 264 |
+
array([False])
|
| 265 |
+
|
| 266 |
+
""")
|
| 267 |
+
|
| 268 |
+
add_newdoc('numpy', 'NAN',
|
| 269 |
+
"""
|
| 270 |
+
IEEE 754 floating point representation of Not a Number (NaN).
|
| 271 |
+
|
| 272 |
+
`NaN` and `NAN` are equivalent definitions of `nan`. Please use
|
| 273 |
+
`nan` instead of `NAN`.
|
| 274 |
+
|
| 275 |
+
See Also
|
| 276 |
+
--------
|
| 277 |
+
nan
|
| 278 |
+
|
| 279 |
+
""")
|
| 280 |
+
|
| 281 |
+
add_newdoc('numpy', 'NaN',
|
| 282 |
+
"""
|
| 283 |
+
IEEE 754 floating point representation of Not a Number (NaN).
|
| 284 |
+
|
| 285 |
+
`NaN` and `NAN` are equivalent definitions of `nan`. Please use
|
| 286 |
+
`nan` instead of `NaN`.
|
| 287 |
+
|
| 288 |
+
See Also
|
| 289 |
+
--------
|
| 290 |
+
nan
|
| 291 |
+
|
| 292 |
+
""")
|
| 293 |
+
|
| 294 |
+
add_newdoc('numpy', 'NINF',
|
| 295 |
+
"""
|
| 296 |
+
IEEE 754 floating point representation of negative infinity.
|
| 297 |
+
|
| 298 |
+
Returns
|
| 299 |
+
-------
|
| 300 |
+
y : float
|
| 301 |
+
A floating point representation of negative infinity.
|
| 302 |
+
|
| 303 |
+
See Also
|
| 304 |
+
--------
|
| 305 |
+
isinf : Shows which elements are positive or negative infinity
|
| 306 |
+
|
| 307 |
+
isposinf : Shows which elements are positive infinity
|
| 308 |
+
|
| 309 |
+
isneginf : Shows which elements are negative infinity
|
| 310 |
+
|
| 311 |
+
isnan : Shows which elements are Not a Number
|
| 312 |
+
|
| 313 |
+
isfinite : Shows which elements are finite (not one of Not a Number,
|
| 314 |
+
positive infinity and negative infinity)
|
| 315 |
+
|
| 316 |
+
Notes
|
| 317 |
+
-----
|
| 318 |
+
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic
|
| 319 |
+
(IEEE 754). This means that Not a Number is not equivalent to infinity.
|
| 320 |
+
Also that positive infinity is not equivalent to negative infinity. But
|
| 321 |
+
infinity is equivalent to positive infinity.
|
| 322 |
+
|
| 323 |
+
Examples
|
| 324 |
+
--------
|
| 325 |
+
>>> np.NINF
|
| 326 |
+
-inf
|
| 327 |
+
>>> np.log(0)
|
| 328 |
+
-inf
|
| 329 |
+
|
| 330 |
+
""")
|
| 331 |
+
|
| 332 |
+
add_newdoc('numpy', 'PINF',
|
| 333 |
+
"""
|
| 334 |
+
IEEE 754 floating point representation of (positive) infinity.
|
| 335 |
+
|
| 336 |
+
Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for
|
| 337 |
+
`inf`. For more details, see `inf`.
|
| 338 |
+
|
| 339 |
+
See Also
|
| 340 |
+
--------
|
| 341 |
+
inf
|
| 342 |
+
|
| 343 |
+
""")
|
| 344 |
+
|
| 345 |
+
add_newdoc('numpy', 'infty',
|
| 346 |
+
"""
|
| 347 |
+
IEEE 754 floating point representation of (positive) infinity.
|
| 348 |
+
|
| 349 |
+
Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for
|
| 350 |
+
`inf`. For more details, see `inf`.
|
| 351 |
+
|
| 352 |
+
See Also
|
| 353 |
+
--------
|
| 354 |
+
inf
|
| 355 |
+
|
| 356 |
+
""")
|
| 357 |
+
|
| 358 |
+
add_newdoc('numpy', 'Inf',
|
| 359 |
+
"""
|
| 360 |
+
IEEE 754 floating point representation of (positive) infinity.
|
| 361 |
+
|
| 362 |
+
Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for
|
| 363 |
+
`inf`. For more details, see `inf`.
|
| 364 |
+
|
| 365 |
+
See Also
|
| 366 |
+
--------
|
| 367 |
+
inf
|
| 368 |
+
|
| 369 |
+
""")
|
| 370 |
+
|
| 371 |
+
add_newdoc('numpy', 'Infinity',
|
| 372 |
+
"""
|
| 373 |
+
IEEE 754 floating point representation of (positive) infinity.
|
| 374 |
+
|
| 375 |
+
Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for
|
| 376 |
+
`inf`. For more details, see `inf`.
|
| 377 |
+
|
| 378 |
+
See Also
|
| 379 |
+
--------
|
| 380 |
+
inf
|
| 381 |
+
|
| 382 |
+
""")
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
if __doc__:
|
| 386 |
+
constants_str = []
|
| 387 |
+
constants.sort()
|
| 388 |
+
for name, doc in constants:
|
| 389 |
+
s = textwrap.dedent(doc).replace("\n", "\n ")
|
| 390 |
+
|
| 391 |
+
# Replace sections by rubrics
|
| 392 |
+
lines = s.split("\n")
|
| 393 |
+
new_lines = []
|
| 394 |
+
for line in lines:
|
| 395 |
+
m = re.match(r'^(\s+)[-=]+\s*$', line)
|
| 396 |
+
if m and new_lines:
|
| 397 |
+
prev = textwrap.dedent(new_lines.pop())
|
| 398 |
+
new_lines.append('%s.. rubric:: %s' % (m.group(1), prev))
|
| 399 |
+
new_lines.append('')
|
| 400 |
+
else:
|
| 401 |
+
new_lines.append(line)
|
| 402 |
+
s = "\n".join(new_lines)
|
| 403 |
+
|
| 404 |
+
# Done.
|
| 405 |
+
constants_str.append(""".. data:: %s\n %s""" % (name, s))
|
| 406 |
+
constants_str = "\n".join(constants_str)
|
| 407 |
+
|
| 408 |
+
__doc__ = __doc__ % dict(constant_list=constants_str)
|
| 409 |
+
del constants_str, name, doc
|
| 410 |
+
del line, lines, new_lines, m, s, prev
|
| 411 |
+
|
| 412 |
+
del constants, add_newdoc
|
.venv/lib/python3.11/site-packages/numpy/doc/ufuncs.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
===================
|
| 3 |
+
Universal Functions
|
| 4 |
+
===================
|
| 5 |
+
|
| 6 |
+
Ufuncs are, generally speaking, mathematical functions or operations that are
|
| 7 |
+
applied element-by-element to the contents of an array. That is, the result
|
| 8 |
+
in each output array element only depends on the value in the corresponding
|
| 9 |
+
input array (or arrays) and on no other array elements. NumPy comes with a
|
| 10 |
+
large suite of ufuncs, and scipy extends that suite substantially. The simplest
|
| 11 |
+
example is the addition operator: ::
|
| 12 |
+
|
| 13 |
+
>>> np.array([0,2,3,4]) + np.array([1,1,-1,2])
|
| 14 |
+
array([1, 3, 2, 6])
|
| 15 |
+
|
| 16 |
+
The ufunc module lists all the available ufuncs in numpy. Documentation on
|
| 17 |
+
the specific ufuncs may be found in those modules. This documentation is
|
| 18 |
+
intended to address the more general aspects of ufuncs common to most of
|
| 19 |
+
them. All of the ufuncs that make use of Python operators (e.g., +, -, etc.)
|
| 20 |
+
have equivalent functions defined (e.g. add() for +)
|
| 21 |
+
|
| 22 |
+
Type coercion
|
| 23 |
+
=============
|
| 24 |
+
|
| 25 |
+
What happens when a binary operator (e.g., +,-,\\*,/, etc) deals with arrays of
|
| 26 |
+
two different types? What is the type of the result? Typically, the result is
|
| 27 |
+
the higher of the two types. For example: ::
|
| 28 |
+
|
| 29 |
+
float32 + float64 -> float64
|
| 30 |
+
int8 + int32 -> int32
|
| 31 |
+
int16 + float32 -> float32
|
| 32 |
+
float32 + complex64 -> complex64
|
| 33 |
+
|
| 34 |
+
There are some less obvious cases generally involving mixes of types
|
| 35 |
+
(e.g. uints, ints and floats) where equal bit sizes for each are not
|
| 36 |
+
capable of saving all the information in a different type of equivalent
|
| 37 |
+
bit size. Some examples are int32 vs float32 or uint32 vs int32.
|
| 38 |
+
Generally, the result is the higher type of larger size than both
|
| 39 |
+
(if available). So: ::
|
| 40 |
+
|
| 41 |
+
int32 + float32 -> float64
|
| 42 |
+
uint32 + int32 -> int64
|
| 43 |
+
|
| 44 |
+
Finally, the type coercion behavior when expressions involve Python
|
| 45 |
+
scalars is different than that seen for arrays. Since Python has a
|
| 46 |
+
limited number of types, combining a Python int with a dtype=np.int8
|
| 47 |
+
array does not coerce to the higher type but instead, the type of the
|
| 48 |
+
array prevails. So the rules for Python scalars combined with arrays is
|
| 49 |
+
that the result will be that of the array equivalent the Python scalar
|
| 50 |
+
if the Python scalar is of a higher 'kind' than the array (e.g., float
|
| 51 |
+
vs. int), otherwise the resultant type will be that of the array.
|
| 52 |
+
For example: ::
|
| 53 |
+
|
| 54 |
+
Python int + int8 -> int8
|
| 55 |
+
Python float + int8 -> float64
|
| 56 |
+
|
| 57 |
+
ufunc methods
|
| 58 |
+
=============
|
| 59 |
+
|
| 60 |
+
Binary ufuncs support 4 methods.
|
| 61 |
+
|
| 62 |
+
**.reduce(arr)** applies the binary operator to elements of the array in
|
| 63 |
+
sequence. For example: ::
|
| 64 |
+
|
| 65 |
+
>>> np.add.reduce(np.arange(10)) # adds all elements of array
|
| 66 |
+
45
|
| 67 |
+
|
| 68 |
+
For multidimensional arrays, the first dimension is reduced by default: ::
|
| 69 |
+
|
| 70 |
+
>>> np.add.reduce(np.arange(10).reshape(2,5))
|
| 71 |
+
array([ 5, 7, 9, 11, 13])
|
| 72 |
+
|
| 73 |
+
The axis keyword can be used to specify different axes to reduce: ::
|
| 74 |
+
|
| 75 |
+
>>> np.add.reduce(np.arange(10).reshape(2,5),axis=1)
|
| 76 |
+
array([10, 35])
|
| 77 |
+
|
| 78 |
+
**.accumulate(arr)** applies the binary operator and generates an
|
| 79 |
+
equivalently shaped array that includes the accumulated amount for each
|
| 80 |
+
element of the array. A couple examples: ::
|
| 81 |
+
|
| 82 |
+
>>> np.add.accumulate(np.arange(10))
|
| 83 |
+
array([ 0, 1, 3, 6, 10, 15, 21, 28, 36, 45])
|
| 84 |
+
>>> np.multiply.accumulate(np.arange(1,9))
|
| 85 |
+
array([ 1, 2, 6, 24, 120, 720, 5040, 40320])
|
| 86 |
+
|
| 87 |
+
The behavior for multidimensional arrays is the same as for .reduce(),
|
| 88 |
+
as is the use of the axis keyword).
|
| 89 |
+
|
| 90 |
+
**.reduceat(arr,indices)** allows one to apply reduce to selected parts
|
| 91 |
+
of an array. It is a difficult method to understand. See the documentation
|
| 92 |
+
at:
|
| 93 |
+
|
| 94 |
+
**.outer(arr1,arr2)** generates an outer operation on the two arrays arr1 and
|
| 95 |
+
arr2. It will work on multidimensional arrays (the shape of the result is
|
| 96 |
+
the concatenation of the two input shapes.: ::
|
| 97 |
+
|
| 98 |
+
>>> np.multiply.outer(np.arange(3),np.arange(4))
|
| 99 |
+
array([[0, 0, 0, 0],
|
| 100 |
+
[0, 1, 2, 3],
|
| 101 |
+
[0, 2, 4, 6]])
|
| 102 |
+
|
| 103 |
+
Output arguments
|
| 104 |
+
================
|
| 105 |
+
|
| 106 |
+
All ufuncs accept an optional output array. The array must be of the expected
|
| 107 |
+
output shape. Beware that if the type of the output array is of a different
|
| 108 |
+
(and lower) type than the output result, the results may be silently truncated
|
| 109 |
+
or otherwise corrupted in the downcast to the lower type. This usage is useful
|
| 110 |
+
when one wants to avoid creating large temporary arrays and instead allows one
|
| 111 |
+
to reuse the same array memory repeatedly (at the expense of not being able to
|
| 112 |
+
use more convenient operator notation in expressions). Note that when the
|
| 113 |
+
output argument is used, the ufunc still returns a reference to the result.
|
| 114 |
+
|
| 115 |
+
>>> x = np.arange(2)
|
| 116 |
+
>>> np.add(np.arange(2),np.arange(2.),x)
|
| 117 |
+
array([0, 2])
|
| 118 |
+
>>> x
|
| 119 |
+
array([0, 2])
|
| 120 |
+
|
| 121 |
+
and & or as ufuncs
|
| 122 |
+
==================
|
| 123 |
+
|
| 124 |
+
Invariably people try to use the python 'and' and 'or' as logical operators
|
| 125 |
+
(and quite understandably). But these operators do not behave as normal
|
| 126 |
+
operators since Python treats these quite differently. They cannot be
|
| 127 |
+
overloaded with array equivalents. Thus using 'and' or 'or' with an array
|
| 128 |
+
results in an error. There are two alternatives:
|
| 129 |
+
|
| 130 |
+
1) use the ufunc functions logical_and() and logical_or().
|
| 131 |
+
2) use the bitwise operators & and \\|. The drawback of these is that if
|
| 132 |
+
the arguments to these operators are not boolean arrays, the result is
|
| 133 |
+
likely incorrect. On the other hand, most usages of logical_and and
|
| 134 |
+
logical_or are with boolean arrays. As long as one is careful, this is
|
| 135 |
+
a convenient way to apply these operators.
|
| 136 |
+
|
| 137 |
+
"""
|
.venv/lib/python3.11/site-packages/numpy/linalg/tests/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (191 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/typing/__init__.py
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
============================
|
| 3 |
+
Typing (:mod:`numpy.typing`)
|
| 4 |
+
============================
|
| 5 |
+
|
| 6 |
+
.. versionadded:: 1.20
|
| 7 |
+
|
| 8 |
+
Large parts of the NumPy API have :pep:`484`-style type annotations. In
|
| 9 |
+
addition a number of type aliases are available to users, most prominently
|
| 10 |
+
the two below:
|
| 11 |
+
|
| 12 |
+
- `ArrayLike`: objects that can be converted to arrays
|
| 13 |
+
- `DTypeLike`: objects that can be converted to dtypes
|
| 14 |
+
|
| 15 |
+
.. _typing-extensions: https://pypi.org/project/typing-extensions/
|
| 16 |
+
|
| 17 |
+
Mypy plugin
|
| 18 |
+
-----------
|
| 19 |
+
|
| 20 |
+
.. versionadded:: 1.21
|
| 21 |
+
|
| 22 |
+
.. automodule:: numpy.typing.mypy_plugin
|
| 23 |
+
|
| 24 |
+
.. currentmodule:: numpy.typing
|
| 25 |
+
|
| 26 |
+
Differences from the runtime NumPy API
|
| 27 |
+
--------------------------------------
|
| 28 |
+
|
| 29 |
+
NumPy is very flexible. Trying to describe the full range of
|
| 30 |
+
possibilities statically would result in types that are not very
|
| 31 |
+
helpful. For that reason, the typed NumPy API is often stricter than
|
| 32 |
+
the runtime NumPy API. This section describes some notable
|
| 33 |
+
differences.
|
| 34 |
+
|
| 35 |
+
ArrayLike
|
| 36 |
+
~~~~~~~~~
|
| 37 |
+
|
| 38 |
+
The `ArrayLike` type tries to avoid creating object arrays. For
|
| 39 |
+
example,
|
| 40 |
+
|
| 41 |
+
.. code-block:: python
|
| 42 |
+
|
| 43 |
+
>>> np.array(x**2 for x in range(10))
|
| 44 |
+
array(<generator object <genexpr> at ...>, dtype=object)
|
| 45 |
+
|
| 46 |
+
is valid NumPy code which will create a 0-dimensional object
|
| 47 |
+
array. Type checkers will complain about the above example when using
|
| 48 |
+
the NumPy types however. If you really intended to do the above, then
|
| 49 |
+
you can either use a ``# type: ignore`` comment:
|
| 50 |
+
|
| 51 |
+
.. code-block:: python
|
| 52 |
+
|
| 53 |
+
>>> np.array(x**2 for x in range(10)) # type: ignore
|
| 54 |
+
|
| 55 |
+
or explicitly type the array like object as `~typing.Any`:
|
| 56 |
+
|
| 57 |
+
.. code-block:: python
|
| 58 |
+
|
| 59 |
+
>>> from typing import Any
|
| 60 |
+
>>> array_like: Any = (x**2 for x in range(10))
|
| 61 |
+
>>> np.array(array_like)
|
| 62 |
+
array(<generator object <genexpr> at ...>, dtype=object)
|
| 63 |
+
|
| 64 |
+
ndarray
|
| 65 |
+
~~~~~~~
|
| 66 |
+
|
| 67 |
+
It's possible to mutate the dtype of an array at runtime. For example,
|
| 68 |
+
the following code is valid:
|
| 69 |
+
|
| 70 |
+
.. code-block:: python
|
| 71 |
+
|
| 72 |
+
>>> x = np.array([1, 2])
|
| 73 |
+
>>> x.dtype = np.bool_
|
| 74 |
+
|
| 75 |
+
This sort of mutation is not allowed by the types. Users who want to
|
| 76 |
+
write statically typed code should instead use the `numpy.ndarray.view`
|
| 77 |
+
method to create a view of the array with a different dtype.
|
| 78 |
+
|
| 79 |
+
DTypeLike
|
| 80 |
+
~~~~~~~~~
|
| 81 |
+
|
| 82 |
+
The `DTypeLike` type tries to avoid creation of dtype objects using
|
| 83 |
+
dictionary of fields like below:
|
| 84 |
+
|
| 85 |
+
.. code-block:: python
|
| 86 |
+
|
| 87 |
+
>>> x = np.dtype({"field1": (float, 1), "field2": (int, 3)})
|
| 88 |
+
|
| 89 |
+
Although this is valid NumPy code, the type checker will complain about it,
|
| 90 |
+
since its usage is discouraged.
|
| 91 |
+
Please see : :ref:`Data type objects <arrays.dtypes>`
|
| 92 |
+
|
| 93 |
+
Number precision
|
| 94 |
+
~~~~~~~~~~~~~~~~
|
| 95 |
+
|
| 96 |
+
The precision of `numpy.number` subclasses is treated as a covariant generic
|
| 97 |
+
parameter (see :class:`~NBitBase`), simplifying the annotating of processes
|
| 98 |
+
involving precision-based casting.
|
| 99 |
+
|
| 100 |
+
.. code-block:: python
|
| 101 |
+
|
| 102 |
+
>>> from typing import TypeVar
|
| 103 |
+
>>> import numpy as np
|
| 104 |
+
>>> import numpy.typing as npt
|
| 105 |
+
|
| 106 |
+
>>> T = TypeVar("T", bound=npt.NBitBase)
|
| 107 |
+
>>> def func(a: "np.floating[T]", b: "np.floating[T]") -> "np.floating[T]":
|
| 108 |
+
... ...
|
| 109 |
+
|
| 110 |
+
Consequently, the likes of `~numpy.float16`, `~numpy.float32` and
|
| 111 |
+
`~numpy.float64` are still sub-types of `~numpy.floating`, but, contrary to
|
| 112 |
+
runtime, they're not necessarily considered as sub-classes.
|
| 113 |
+
|
| 114 |
+
Timedelta64
|
| 115 |
+
~~~~~~~~~~~
|
| 116 |
+
|
| 117 |
+
The `~numpy.timedelta64` class is not considered a subclass of
|
| 118 |
+
`~numpy.signedinteger`, the former only inheriting from `~numpy.generic`
|
| 119 |
+
while static type checking.
|
| 120 |
+
|
| 121 |
+
0D arrays
|
| 122 |
+
~~~~~~~~~
|
| 123 |
+
|
| 124 |
+
During runtime numpy aggressively casts any passed 0D arrays into their
|
| 125 |
+
corresponding `~numpy.generic` instance. Until the introduction of shape
|
| 126 |
+
typing (see :pep:`646`) it is unfortunately not possible to make the
|
| 127 |
+
necessary distinction between 0D and >0D arrays. While thus not strictly
|
| 128 |
+
correct, all operations are that can potentially perform a 0D-array -> scalar
|
| 129 |
+
cast are currently annotated as exclusively returning an `ndarray`.
|
| 130 |
+
|
| 131 |
+
If it is known in advance that an operation _will_ perform a
|
| 132 |
+
0D-array -> scalar cast, then one can consider manually remedying the
|
| 133 |
+
situation with either `typing.cast` or a ``# type: ignore`` comment.
|
| 134 |
+
|
| 135 |
+
Record array dtypes
|
| 136 |
+
~~~~~~~~~~~~~~~~~~~
|
| 137 |
+
|
| 138 |
+
The dtype of `numpy.recarray`, and the `numpy.rec` functions in general,
|
| 139 |
+
can be specified in one of two ways:
|
| 140 |
+
|
| 141 |
+
* Directly via the ``dtype`` argument.
|
| 142 |
+
* With up to five helper arguments that operate via `numpy.format_parser`:
|
| 143 |
+
``formats``, ``names``, ``titles``, ``aligned`` and ``byteorder``.
|
| 144 |
+
|
| 145 |
+
These two approaches are currently typed as being mutually exclusive,
|
| 146 |
+
*i.e.* if ``dtype`` is specified than one may not specify ``formats``.
|
| 147 |
+
While this mutual exclusivity is not (strictly) enforced during runtime,
|
| 148 |
+
combining both dtype specifiers can lead to unexpected or even downright
|
| 149 |
+
buggy behavior.
|
| 150 |
+
|
| 151 |
+
API
|
| 152 |
+
---
|
| 153 |
+
|
| 154 |
+
"""
|
| 155 |
+
# NOTE: The API section will be appended with additional entries
|
| 156 |
+
# further down in this file
|
| 157 |
+
|
| 158 |
+
from numpy._typing import (
|
| 159 |
+
ArrayLike,
|
| 160 |
+
DTypeLike,
|
| 161 |
+
NBitBase,
|
| 162 |
+
NDArray,
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
__all__ = ["ArrayLike", "DTypeLike", "NBitBase", "NDArray"]
|
| 166 |
+
|
| 167 |
+
if __doc__ is not None:
|
| 168 |
+
from numpy._typing._add_docstring import _docstrings
|
| 169 |
+
__doc__ += _docstrings
|
| 170 |
+
__doc__ += '\n.. autoclass:: numpy.typing.NBitBase\n'
|
| 171 |
+
del _docstrings
|
| 172 |
+
|
| 173 |
+
from numpy._pytesttester import PytestTester
|
| 174 |
+
test = PytestTester(__name__)
|
| 175 |
+
del PytestTester
|
.venv/lib/python3.11/site-packages/numpy/typing/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (5.42 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/typing/__pycache__/mypy_plugin.cpython-311.pyc
ADDED
|
Binary file (8.71 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/typing/__pycache__/setup.cpython-311.pyc
ADDED
|
Binary file (839 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/numpy/typing/mypy_plugin.py
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A mypy_ plugin for managing a number of platform-specific annotations.
|
| 2 |
+
Its functionality can be split into three distinct parts:
|
| 3 |
+
|
| 4 |
+
* Assigning the (platform-dependent) precisions of certain `~numpy.number`
|
| 5 |
+
subclasses, including the likes of `~numpy.int_`, `~numpy.intp` and
|
| 6 |
+
`~numpy.longlong`. See the documentation on
|
| 7 |
+
:ref:`scalar types <arrays.scalars.built-in>` for a comprehensive overview
|
| 8 |
+
of the affected classes. Without the plugin the precision of all relevant
|
| 9 |
+
classes will be inferred as `~typing.Any`.
|
| 10 |
+
* Removing all extended-precision `~numpy.number` subclasses that are
|
| 11 |
+
unavailable for the platform in question. Most notably this includes the
|
| 12 |
+
likes of `~numpy.float128` and `~numpy.complex256`. Without the plugin *all*
|
| 13 |
+
extended-precision types will, as far as mypy is concerned, be available
|
| 14 |
+
to all platforms.
|
| 15 |
+
* Assigning the (platform-dependent) precision of `~numpy.ctypeslib.c_intp`.
|
| 16 |
+
Without the plugin the type will default to `ctypes.c_int64`.
|
| 17 |
+
|
| 18 |
+
.. versionadded:: 1.22
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
--------
|
| 22 |
+
To enable the plugin, one must add it to their mypy `configuration file`_:
|
| 23 |
+
|
| 24 |
+
.. code-block:: ini
|
| 25 |
+
|
| 26 |
+
[mypy]
|
| 27 |
+
plugins = numpy.typing.mypy_plugin
|
| 28 |
+
|
| 29 |
+
.. _mypy: http://mypy-lang.org/
|
| 30 |
+
.. _configuration file: https://mypy.readthedocs.io/en/stable/config_file.html
|
| 31 |
+
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
from __future__ import annotations
|
| 35 |
+
|
| 36 |
+
from collections.abc import Iterable
|
| 37 |
+
from typing import Final, TYPE_CHECKING, Callable
|
| 38 |
+
|
| 39 |
+
import numpy as np
|
| 40 |
+
|
| 41 |
+
try:
|
| 42 |
+
import mypy.types
|
| 43 |
+
from mypy.types import Type
|
| 44 |
+
from mypy.plugin import Plugin, AnalyzeTypeContext
|
| 45 |
+
from mypy.nodes import MypyFile, ImportFrom, Statement
|
| 46 |
+
from mypy.build import PRI_MED
|
| 47 |
+
|
| 48 |
+
_HookFunc = Callable[[AnalyzeTypeContext], Type]
|
| 49 |
+
MYPY_EX: None | ModuleNotFoundError = None
|
| 50 |
+
except ModuleNotFoundError as ex:
|
| 51 |
+
MYPY_EX = ex
|
| 52 |
+
|
| 53 |
+
__all__: list[str] = []
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def _get_precision_dict() -> dict[str, str]:
|
| 57 |
+
names = [
|
| 58 |
+
("_NBitByte", np.byte),
|
| 59 |
+
("_NBitShort", np.short),
|
| 60 |
+
("_NBitIntC", np.intc),
|
| 61 |
+
("_NBitIntP", np.intp),
|
| 62 |
+
("_NBitInt", np.int_),
|
| 63 |
+
("_NBitLongLong", np.longlong),
|
| 64 |
+
|
| 65 |
+
("_NBitHalf", np.half),
|
| 66 |
+
("_NBitSingle", np.single),
|
| 67 |
+
("_NBitDouble", np.double),
|
| 68 |
+
("_NBitLongDouble", np.longdouble),
|
| 69 |
+
]
|
| 70 |
+
ret = {}
|
| 71 |
+
for name, typ in names:
|
| 72 |
+
n: int = 8 * typ().dtype.itemsize
|
| 73 |
+
ret[f'numpy._typing._nbit.{name}'] = f"numpy._{n}Bit"
|
| 74 |
+
return ret
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def _get_extended_precision_list() -> list[str]:
|
| 78 |
+
extended_names = [
|
| 79 |
+
"uint128",
|
| 80 |
+
"uint256",
|
| 81 |
+
"int128",
|
| 82 |
+
"int256",
|
| 83 |
+
"float80",
|
| 84 |
+
"float96",
|
| 85 |
+
"float128",
|
| 86 |
+
"float256",
|
| 87 |
+
"complex160",
|
| 88 |
+
"complex192",
|
| 89 |
+
"complex256",
|
| 90 |
+
"complex512",
|
| 91 |
+
]
|
| 92 |
+
return [i for i in extended_names if hasattr(np, i)]
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def _get_c_intp_name() -> str:
|
| 96 |
+
# Adapted from `np.core._internal._getintp_ctype`
|
| 97 |
+
char = np.dtype('p').char
|
| 98 |
+
if char == 'i':
|
| 99 |
+
return "c_int"
|
| 100 |
+
elif char == 'l':
|
| 101 |
+
return "c_long"
|
| 102 |
+
elif char == 'q':
|
| 103 |
+
return "c_longlong"
|
| 104 |
+
else:
|
| 105 |
+
return "c_long"
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
#: A dictionary mapping type-aliases in `numpy._typing._nbit` to
|
| 109 |
+
#: concrete `numpy.typing.NBitBase` subclasses.
|
| 110 |
+
_PRECISION_DICT: Final = _get_precision_dict()
|
| 111 |
+
|
| 112 |
+
#: A list with the names of all extended precision `np.number` subclasses.
|
| 113 |
+
_EXTENDED_PRECISION_LIST: Final = _get_extended_precision_list()
|
| 114 |
+
|
| 115 |
+
#: The name of the ctypes quivalent of `np.intp`
|
| 116 |
+
_C_INTP: Final = _get_c_intp_name()
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def _hook(ctx: AnalyzeTypeContext) -> Type:
|
| 120 |
+
"""Replace a type-alias with a concrete ``NBitBase`` subclass."""
|
| 121 |
+
typ, _, api = ctx
|
| 122 |
+
name = typ.name.split(".")[-1]
|
| 123 |
+
name_new = _PRECISION_DICT[f"numpy._typing._nbit.{name}"]
|
| 124 |
+
return api.named_type(name_new)
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
if TYPE_CHECKING or MYPY_EX is None:
|
| 128 |
+
def _index(iterable: Iterable[Statement], id: str) -> int:
|
| 129 |
+
"""Identify the first ``ImportFrom`` instance the specified `id`."""
|
| 130 |
+
for i, value in enumerate(iterable):
|
| 131 |
+
if getattr(value, "id", None) == id:
|
| 132 |
+
return i
|
| 133 |
+
raise ValueError("Failed to identify a `ImportFrom` instance "
|
| 134 |
+
f"with the following id: {id!r}")
|
| 135 |
+
|
| 136 |
+
def _override_imports(
|
| 137 |
+
file: MypyFile,
|
| 138 |
+
module: str,
|
| 139 |
+
imports: list[tuple[str, None | str]],
|
| 140 |
+
) -> None:
|
| 141 |
+
"""Override the first `module`-based import with new `imports`."""
|
| 142 |
+
# Construct a new `from module import y` statement
|
| 143 |
+
import_obj = ImportFrom(module, 0, names=imports)
|
| 144 |
+
import_obj.is_top_level = True
|
| 145 |
+
|
| 146 |
+
# Replace the first `module`-based import statement with `import_obj`
|
| 147 |
+
for lst in [file.defs, file.imports]: # type: list[Statement]
|
| 148 |
+
i = _index(lst, module)
|
| 149 |
+
lst[i] = import_obj
|
| 150 |
+
|
| 151 |
+
class _NumpyPlugin(Plugin):
|
| 152 |
+
"""A mypy plugin for handling versus numpy-specific typing tasks."""
|
| 153 |
+
|
| 154 |
+
def get_type_analyze_hook(self, fullname: str) -> None | _HookFunc:
|
| 155 |
+
"""Set the precision of platform-specific `numpy.number`
|
| 156 |
+
subclasses.
|
| 157 |
+
|
| 158 |
+
For example: `numpy.int_`, `numpy.longlong` and `numpy.longdouble`.
|
| 159 |
+
"""
|
| 160 |
+
if fullname in _PRECISION_DICT:
|
| 161 |
+
return _hook
|
| 162 |
+
return None
|
| 163 |
+
|
| 164 |
+
def get_additional_deps(
|
| 165 |
+
self, file: MypyFile
|
| 166 |
+
) -> list[tuple[int, str, int]]:
|
| 167 |
+
"""Handle all import-based overrides.
|
| 168 |
+
|
| 169 |
+
* Import platform-specific extended-precision `numpy.number`
|
| 170 |
+
subclasses (*e.g.* `numpy.float96`, `numpy.float128` and
|
| 171 |
+
`numpy.complex256`).
|
| 172 |
+
* Import the appropriate `ctypes` equivalent to `numpy.intp`.
|
| 173 |
+
|
| 174 |
+
"""
|
| 175 |
+
ret = [(PRI_MED, file.fullname, -1)]
|
| 176 |
+
|
| 177 |
+
if file.fullname == "numpy":
|
| 178 |
+
_override_imports(
|
| 179 |
+
file, "numpy._typing._extended_precision",
|
| 180 |
+
imports=[(v, v) for v in _EXTENDED_PRECISION_LIST],
|
| 181 |
+
)
|
| 182 |
+
elif file.fullname == "numpy.ctypeslib":
|
| 183 |
+
_override_imports(
|
| 184 |
+
file, "ctypes",
|
| 185 |
+
imports=[(_C_INTP, "_c_intp")],
|
| 186 |
+
)
|
| 187 |
+
return ret
|
| 188 |
+
|
| 189 |
+
def plugin(version: str) -> type[_NumpyPlugin]:
|
| 190 |
+
"""An entry-point for mypy."""
|
| 191 |
+
return _NumpyPlugin
|
| 192 |
+
|
| 193 |
+
else:
|
| 194 |
+
def plugin(version: str) -> type[_NumpyPlugin]:
|
| 195 |
+
"""An entry-point for mypy."""
|
| 196 |
+
raise MYPY_EX
|
.venv/lib/python3.11/site-packages/numpy/typing/setup.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def configuration(parent_package='', top_path=None):
|
| 2 |
+
from numpy.distutils.misc_util import Configuration
|
| 3 |
+
config = Configuration('typing', parent_package, top_path)
|
| 4 |
+
config.add_subpackage('tests')
|
| 5 |
+
config.add_data_dir('tests/data')
|
| 6 |
+
return config
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
if __name__ == '__main__':
|
| 10 |
+
from numpy.distutils.core import setup
|
| 11 |
+
setup(configuration=configuration)
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/__init__.py
ADDED
|
File without changes
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/arithmetic.pyi
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
b_ = np.bool_()
|
| 5 |
+
dt = np.datetime64(0, "D")
|
| 6 |
+
td = np.timedelta64(0, "D")
|
| 7 |
+
|
| 8 |
+
AR_b: np.ndarray[Any, np.dtype[np.bool_]]
|
| 9 |
+
AR_u: np.ndarray[Any, np.dtype[np.uint32]]
|
| 10 |
+
AR_i: np.ndarray[Any, np.dtype[np.int64]]
|
| 11 |
+
AR_f: np.ndarray[Any, np.dtype[np.float64]]
|
| 12 |
+
AR_c: np.ndarray[Any, np.dtype[np.complex128]]
|
| 13 |
+
AR_m: np.ndarray[Any, np.dtype[np.timedelta64]]
|
| 14 |
+
AR_M: np.ndarray[Any, np.dtype[np.datetime64]]
|
| 15 |
+
|
| 16 |
+
ANY: Any
|
| 17 |
+
|
| 18 |
+
AR_LIKE_b: list[bool]
|
| 19 |
+
AR_LIKE_u: list[np.uint32]
|
| 20 |
+
AR_LIKE_i: list[int]
|
| 21 |
+
AR_LIKE_f: list[float]
|
| 22 |
+
AR_LIKE_c: list[complex]
|
| 23 |
+
AR_LIKE_m: list[np.timedelta64]
|
| 24 |
+
AR_LIKE_M: list[np.datetime64]
|
| 25 |
+
|
| 26 |
+
# Array subtraction
|
| 27 |
+
|
| 28 |
+
# NOTE: mypys `NoReturn` errors are, unfortunately, not that great
|
| 29 |
+
_1 = AR_b - AR_LIKE_b # E: Need type annotation
|
| 30 |
+
_2 = AR_LIKE_b - AR_b # E: Need type annotation
|
| 31 |
+
AR_i - bytes() # E: No overload variant
|
| 32 |
+
|
| 33 |
+
AR_f - AR_LIKE_m # E: Unsupported operand types
|
| 34 |
+
AR_f - AR_LIKE_M # E: Unsupported operand types
|
| 35 |
+
AR_c - AR_LIKE_m # E: Unsupported operand types
|
| 36 |
+
AR_c - AR_LIKE_M # E: Unsupported operand types
|
| 37 |
+
|
| 38 |
+
AR_m - AR_LIKE_f # E: Unsupported operand types
|
| 39 |
+
AR_M - AR_LIKE_f # E: Unsupported operand types
|
| 40 |
+
AR_m - AR_LIKE_c # E: Unsupported operand types
|
| 41 |
+
AR_M - AR_LIKE_c # E: Unsupported operand types
|
| 42 |
+
|
| 43 |
+
AR_m - AR_LIKE_M # E: Unsupported operand types
|
| 44 |
+
AR_LIKE_m - AR_M # E: Unsupported operand types
|
| 45 |
+
|
| 46 |
+
# array floor division
|
| 47 |
+
|
| 48 |
+
AR_M // AR_LIKE_b # E: Unsupported operand types
|
| 49 |
+
AR_M // AR_LIKE_u # E: Unsupported operand types
|
| 50 |
+
AR_M // AR_LIKE_i # E: Unsupported operand types
|
| 51 |
+
AR_M // AR_LIKE_f # E: Unsupported operand types
|
| 52 |
+
AR_M // AR_LIKE_c # E: Unsupported operand types
|
| 53 |
+
AR_M // AR_LIKE_m # E: Unsupported operand types
|
| 54 |
+
AR_M // AR_LIKE_M # E: Unsupported operand types
|
| 55 |
+
|
| 56 |
+
AR_b // AR_LIKE_M # E: Unsupported operand types
|
| 57 |
+
AR_u // AR_LIKE_M # E: Unsupported operand types
|
| 58 |
+
AR_i // AR_LIKE_M # E: Unsupported operand types
|
| 59 |
+
AR_f // AR_LIKE_M # E: Unsupported operand types
|
| 60 |
+
AR_c // AR_LIKE_M # E: Unsupported operand types
|
| 61 |
+
AR_m // AR_LIKE_M # E: Unsupported operand types
|
| 62 |
+
AR_M // AR_LIKE_M # E: Unsupported operand types
|
| 63 |
+
|
| 64 |
+
_3 = AR_m // AR_LIKE_b # E: Need type annotation
|
| 65 |
+
AR_m // AR_LIKE_c # E: Unsupported operand types
|
| 66 |
+
|
| 67 |
+
AR_b // AR_LIKE_m # E: Unsupported operand types
|
| 68 |
+
AR_u // AR_LIKE_m # E: Unsupported operand types
|
| 69 |
+
AR_i // AR_LIKE_m # E: Unsupported operand types
|
| 70 |
+
AR_f // AR_LIKE_m # E: Unsupported operand types
|
| 71 |
+
AR_c // AR_LIKE_m # E: Unsupported operand types
|
| 72 |
+
|
| 73 |
+
# Array multiplication
|
| 74 |
+
|
| 75 |
+
AR_b *= AR_LIKE_u # E: incompatible type
|
| 76 |
+
AR_b *= AR_LIKE_i # E: incompatible type
|
| 77 |
+
AR_b *= AR_LIKE_f # E: incompatible type
|
| 78 |
+
AR_b *= AR_LIKE_c # E: incompatible type
|
| 79 |
+
AR_b *= AR_LIKE_m # E: incompatible type
|
| 80 |
+
|
| 81 |
+
AR_u *= AR_LIKE_i # E: incompatible type
|
| 82 |
+
AR_u *= AR_LIKE_f # E: incompatible type
|
| 83 |
+
AR_u *= AR_LIKE_c # E: incompatible type
|
| 84 |
+
AR_u *= AR_LIKE_m # E: incompatible type
|
| 85 |
+
|
| 86 |
+
AR_i *= AR_LIKE_f # E: incompatible type
|
| 87 |
+
AR_i *= AR_LIKE_c # E: incompatible type
|
| 88 |
+
AR_i *= AR_LIKE_m # E: incompatible type
|
| 89 |
+
|
| 90 |
+
AR_f *= AR_LIKE_c # E: incompatible type
|
| 91 |
+
AR_f *= AR_LIKE_m # E: incompatible type
|
| 92 |
+
|
| 93 |
+
# Array power
|
| 94 |
+
|
| 95 |
+
AR_b **= AR_LIKE_b # E: Invalid self argument
|
| 96 |
+
AR_b **= AR_LIKE_u # E: Invalid self argument
|
| 97 |
+
AR_b **= AR_LIKE_i # E: Invalid self argument
|
| 98 |
+
AR_b **= AR_LIKE_f # E: Invalid self argument
|
| 99 |
+
AR_b **= AR_LIKE_c # E: Invalid self argument
|
| 100 |
+
|
| 101 |
+
AR_u **= AR_LIKE_i # E: incompatible type
|
| 102 |
+
AR_u **= AR_LIKE_f # E: incompatible type
|
| 103 |
+
AR_u **= AR_LIKE_c # E: incompatible type
|
| 104 |
+
|
| 105 |
+
AR_i **= AR_LIKE_f # E: incompatible type
|
| 106 |
+
AR_i **= AR_LIKE_c # E: incompatible type
|
| 107 |
+
|
| 108 |
+
AR_f **= AR_LIKE_c # E: incompatible type
|
| 109 |
+
|
| 110 |
+
# Scalars
|
| 111 |
+
|
| 112 |
+
b_ - b_ # E: No overload variant
|
| 113 |
+
|
| 114 |
+
dt + dt # E: Unsupported operand types
|
| 115 |
+
td - dt # E: Unsupported operand types
|
| 116 |
+
td % 1 # E: Unsupported operand types
|
| 117 |
+
td / dt # E: No overload
|
| 118 |
+
td % dt # E: Unsupported operand types
|
| 119 |
+
|
| 120 |
+
-b_ # E: Unsupported operand type
|
| 121 |
+
+b_ # E: Unsupported operand type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/array_constructors.pyi
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
a: np.ndarray
|
| 4 |
+
generator = (i for i in range(10))
|
| 5 |
+
|
| 6 |
+
np.require(a, requirements=1) # E: No overload variant
|
| 7 |
+
np.require(a, requirements="TEST") # E: incompatible type
|
| 8 |
+
|
| 9 |
+
np.zeros("test") # E: incompatible type
|
| 10 |
+
np.zeros() # E: require at least one argument
|
| 11 |
+
|
| 12 |
+
np.ones("test") # E: incompatible type
|
| 13 |
+
np.ones() # E: require at least one argument
|
| 14 |
+
|
| 15 |
+
np.array(0, float, True) # E: No overload variant
|
| 16 |
+
|
| 17 |
+
np.linspace(None, 'bob') # E: No overload variant
|
| 18 |
+
np.linspace(0, 2, num=10.0) # E: No overload variant
|
| 19 |
+
np.linspace(0, 2, endpoint='True') # E: No overload variant
|
| 20 |
+
np.linspace(0, 2, retstep=b'False') # E: No overload variant
|
| 21 |
+
np.linspace(0, 2, dtype=0) # E: No overload variant
|
| 22 |
+
np.linspace(0, 2, axis=None) # E: No overload variant
|
| 23 |
+
|
| 24 |
+
np.logspace(None, 'bob') # E: No overload variant
|
| 25 |
+
np.logspace(0, 2, base=None) # E: No overload variant
|
| 26 |
+
|
| 27 |
+
np.geomspace(None, 'bob') # E: No overload variant
|
| 28 |
+
|
| 29 |
+
np.stack(generator) # E: No overload variant
|
| 30 |
+
np.hstack({1, 2}) # E: No overload variant
|
| 31 |
+
np.vstack(1) # E: No overload variant
|
| 32 |
+
|
| 33 |
+
np.array([1], like=1) # E: No overload variant
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/array_like.pyi
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from numpy._typing import ArrayLike
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class A:
|
| 6 |
+
pass
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
x1: ArrayLike = (i for i in range(10)) # E: Incompatible types in assignment
|
| 10 |
+
x2: ArrayLike = A() # E: Incompatible types in assignment
|
| 11 |
+
x3: ArrayLike = {1: "foo", 2: "bar"} # E: Incompatible types in assignment
|
| 12 |
+
|
| 13 |
+
scalar = np.int64(1)
|
| 14 |
+
scalar.__array__(dtype=np.float64) # E: No overload variant
|
| 15 |
+
array = np.array([1])
|
| 16 |
+
array.__array__(dtype=np.float64) # E: No overload variant
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/array_pad.pyi
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import numpy.typing as npt
|
| 3 |
+
|
| 4 |
+
AR_i8: npt.NDArray[np.int64]
|
| 5 |
+
|
| 6 |
+
np.pad(AR_i8, 2, mode="bob") # E: No overload variant
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/arrayprint.pyi
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Callable
|
| 2 |
+
from typing import Any
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
AR: np.ndarray
|
| 6 |
+
func1: Callable[[Any], str]
|
| 7 |
+
func2: Callable[[np.integer[Any]], str]
|
| 8 |
+
|
| 9 |
+
np.array2string(AR, style=None) # E: Unexpected keyword argument
|
| 10 |
+
np.array2string(AR, legacy="1.14") # E: incompatible type
|
| 11 |
+
np.array2string(AR, sign="*") # E: incompatible type
|
| 12 |
+
np.array2string(AR, floatmode="default") # E: incompatible type
|
| 13 |
+
np.array2string(AR, formatter={"A": func1}) # E: incompatible type
|
| 14 |
+
np.array2string(AR, formatter={"float": func2}) # E: Incompatible types
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/arrayterator.pyi
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
AR_i8: np.ndarray[Any, np.dtype[np.int64]]
|
| 5 |
+
ar_iter = np.lib.Arrayterator(AR_i8)
|
| 6 |
+
|
| 7 |
+
np.lib.Arrayterator(np.int64()) # E: incompatible type
|
| 8 |
+
ar_iter.shape = (10, 5) # E: is read-only
|
| 9 |
+
ar_iter[None] # E: Invalid index type
|
| 10 |
+
ar_iter[None, 1] # E: Invalid index type
|
| 11 |
+
ar_iter[np.intp()] # E: Invalid index type
|
| 12 |
+
ar_iter[np.intp(), ...] # E: Invalid index type
|
| 13 |
+
ar_iter[AR_i8] # E: Invalid index type
|
| 14 |
+
ar_iter[AR_i8, :] # E: Invalid index type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/bitwise_ops.pyi
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
i8 = np.int64()
|
| 4 |
+
i4 = np.int32()
|
| 5 |
+
u8 = np.uint64()
|
| 6 |
+
b_ = np.bool_()
|
| 7 |
+
i = int()
|
| 8 |
+
|
| 9 |
+
f8 = np.float64()
|
| 10 |
+
|
| 11 |
+
b_ >> f8 # E: No overload variant
|
| 12 |
+
i8 << f8 # E: No overload variant
|
| 13 |
+
i | f8 # E: Unsupported operand types
|
| 14 |
+
i8 ^ f8 # E: No overload variant
|
| 15 |
+
u8 & f8 # E: No overload variant
|
| 16 |
+
~f8 # E: Unsupported operand type
|
| 17 |
+
|
| 18 |
+
# mypys' error message for `NoReturn` is unfortunately pretty bad
|
| 19 |
+
# TODO: Re-enable this once we add support for numerical precision for `number`s
|
| 20 |
+
# a = u8 | 0 # E: Need type annotation
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/char.pyi
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import numpy.typing as npt
|
| 3 |
+
|
| 4 |
+
AR_U: npt.NDArray[np.str_]
|
| 5 |
+
AR_S: npt.NDArray[np.bytes_]
|
| 6 |
+
|
| 7 |
+
np.char.equal(AR_U, AR_S) # E: incompatible type
|
| 8 |
+
|
| 9 |
+
np.char.not_equal(AR_U, AR_S) # E: incompatible type
|
| 10 |
+
|
| 11 |
+
np.char.greater_equal(AR_U, AR_S) # E: incompatible type
|
| 12 |
+
|
| 13 |
+
np.char.less_equal(AR_U, AR_S) # E: incompatible type
|
| 14 |
+
|
| 15 |
+
np.char.greater(AR_U, AR_S) # E: incompatible type
|
| 16 |
+
|
| 17 |
+
np.char.less(AR_U, AR_S) # E: incompatible type
|
| 18 |
+
|
| 19 |
+
np.char.encode(AR_S) # E: incompatible type
|
| 20 |
+
np.char.decode(AR_U) # E: incompatible type
|
| 21 |
+
|
| 22 |
+
np.char.join(AR_U, b"_") # E: incompatible type
|
| 23 |
+
np.char.join(AR_S, "_") # E: incompatible type
|
| 24 |
+
|
| 25 |
+
np.char.ljust(AR_U, 5, fillchar=b"a") # E: incompatible type
|
| 26 |
+
np.char.ljust(AR_S, 5, fillchar="a") # E: incompatible type
|
| 27 |
+
np.char.rjust(AR_U, 5, fillchar=b"a") # E: incompatible type
|
| 28 |
+
np.char.rjust(AR_S, 5, fillchar="a") # E: incompatible type
|
| 29 |
+
|
| 30 |
+
np.char.lstrip(AR_U, chars=b"a") # E: incompatible type
|
| 31 |
+
np.char.lstrip(AR_S, chars="a") # E: incompatible type
|
| 32 |
+
np.char.strip(AR_U, chars=b"a") # E: incompatible type
|
| 33 |
+
np.char.strip(AR_S, chars="a") # E: incompatible type
|
| 34 |
+
np.char.rstrip(AR_U, chars=b"a") # E: incompatible type
|
| 35 |
+
np.char.rstrip(AR_S, chars="a") # E: incompatible type
|
| 36 |
+
|
| 37 |
+
np.char.partition(AR_U, b"a") # E: incompatible type
|
| 38 |
+
np.char.partition(AR_S, "a") # E: incompatible type
|
| 39 |
+
np.char.rpartition(AR_U, b"a") # E: incompatible type
|
| 40 |
+
np.char.rpartition(AR_S, "a") # E: incompatible type
|
| 41 |
+
|
| 42 |
+
np.char.replace(AR_U, b"_", b"-") # E: incompatible type
|
| 43 |
+
np.char.replace(AR_S, "_", "-") # E: incompatible type
|
| 44 |
+
|
| 45 |
+
np.char.split(AR_U, b"_") # E: incompatible type
|
| 46 |
+
np.char.split(AR_S, "_") # E: incompatible type
|
| 47 |
+
np.char.rsplit(AR_U, b"_") # E: incompatible type
|
| 48 |
+
np.char.rsplit(AR_S, "_") # E: incompatible type
|
| 49 |
+
|
| 50 |
+
np.char.count(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
| 51 |
+
np.char.count(AR_S, "a", end=9) # E: incompatible type
|
| 52 |
+
|
| 53 |
+
np.char.endswith(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
| 54 |
+
np.char.endswith(AR_S, "a", end=9) # E: incompatible type
|
| 55 |
+
np.char.startswith(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
| 56 |
+
np.char.startswith(AR_S, "a", end=9) # E: incompatible type
|
| 57 |
+
|
| 58 |
+
np.char.find(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
| 59 |
+
np.char.find(AR_S, "a", end=9) # E: incompatible type
|
| 60 |
+
np.char.rfind(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
| 61 |
+
np.char.rfind(AR_S, "a", end=9) # E: incompatible type
|
| 62 |
+
|
| 63 |
+
np.char.index(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
| 64 |
+
np.char.index(AR_S, "a", end=9) # E: incompatible type
|
| 65 |
+
np.char.rindex(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
| 66 |
+
np.char.rindex(AR_S, "a", end=9) # E: incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/chararray.pyi
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from typing import Any
|
| 3 |
+
|
| 4 |
+
AR_U: np.chararray[Any, np.dtype[np.str_]]
|
| 5 |
+
AR_S: np.chararray[Any, np.dtype[np.bytes_]]
|
| 6 |
+
|
| 7 |
+
AR_S.encode() # E: Invalid self argument
|
| 8 |
+
AR_U.decode() # E: Invalid self argument
|
| 9 |
+
|
| 10 |
+
AR_U.join(b"_") # E: incompatible type
|
| 11 |
+
AR_S.join("_") # E: incompatible type
|
| 12 |
+
|
| 13 |
+
AR_U.ljust(5, fillchar=b"a") # E: incompatible type
|
| 14 |
+
AR_S.ljust(5, fillchar="a") # E: incompatible type
|
| 15 |
+
AR_U.rjust(5, fillchar=b"a") # E: incompatible type
|
| 16 |
+
AR_S.rjust(5, fillchar="a") # E: incompatible type
|
| 17 |
+
|
| 18 |
+
AR_U.lstrip(chars=b"a") # E: incompatible type
|
| 19 |
+
AR_S.lstrip(chars="a") # E: incompatible type
|
| 20 |
+
AR_U.strip(chars=b"a") # E: incompatible type
|
| 21 |
+
AR_S.strip(chars="a") # E: incompatible type
|
| 22 |
+
AR_U.rstrip(chars=b"a") # E: incompatible type
|
| 23 |
+
AR_S.rstrip(chars="a") # E: incompatible type
|
| 24 |
+
|
| 25 |
+
AR_U.partition(b"a") # E: incompatible type
|
| 26 |
+
AR_S.partition("a") # E: incompatible type
|
| 27 |
+
AR_U.rpartition(b"a") # E: incompatible type
|
| 28 |
+
AR_S.rpartition("a") # E: incompatible type
|
| 29 |
+
|
| 30 |
+
AR_U.replace(b"_", b"-") # E: incompatible type
|
| 31 |
+
AR_S.replace("_", "-") # E: incompatible type
|
| 32 |
+
|
| 33 |
+
AR_U.split(b"_") # E: incompatible type
|
| 34 |
+
AR_S.split("_") # E: incompatible type
|
| 35 |
+
AR_S.split(1) # E: incompatible type
|
| 36 |
+
AR_U.rsplit(b"_") # E: incompatible type
|
| 37 |
+
AR_S.rsplit("_") # E: incompatible type
|
| 38 |
+
|
| 39 |
+
AR_U.count(b"a", start=[1, 2, 3]) # E: incompatible type
|
| 40 |
+
AR_S.count("a", end=9) # E: incompatible type
|
| 41 |
+
|
| 42 |
+
AR_U.endswith(b"a", start=[1, 2, 3]) # E: incompatible type
|
| 43 |
+
AR_S.endswith("a", end=9) # E: incompatible type
|
| 44 |
+
AR_U.startswith(b"a", start=[1, 2, 3]) # E: incompatible type
|
| 45 |
+
AR_S.startswith("a", end=9) # E: incompatible type
|
| 46 |
+
|
| 47 |
+
AR_U.find(b"a", start=[1, 2, 3]) # E: incompatible type
|
| 48 |
+
AR_S.find("a", end=9) # E: incompatible type
|
| 49 |
+
AR_U.rfind(b"a", start=[1, 2, 3]) # E: incompatible type
|
| 50 |
+
AR_S.rfind("a", end=9) # E: incompatible type
|
| 51 |
+
|
| 52 |
+
AR_U.index(b"a", start=[1, 2, 3]) # E: incompatible type
|
| 53 |
+
AR_S.index("a", end=9) # E: incompatible type
|
| 54 |
+
AR_U.rindex(b"a", start=[1, 2, 3]) # E: incompatible type
|
| 55 |
+
AR_S.rindex("a", end=9) # E: incompatible type
|
| 56 |
+
|
| 57 |
+
AR_U == AR_S # E: Unsupported operand types
|
| 58 |
+
AR_U != AR_S # E: Unsupported operand types
|
| 59 |
+
AR_U >= AR_S # E: Unsupported operand types
|
| 60 |
+
AR_U <= AR_S # E: Unsupported operand types
|
| 61 |
+
AR_U > AR_S # E: Unsupported operand types
|
| 62 |
+
AR_U < AR_S # E: Unsupported operand types
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/comparisons.pyi
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
AR_i: np.ndarray[Any, np.dtype[np.int64]]
|
| 5 |
+
AR_f: np.ndarray[Any, np.dtype[np.float64]]
|
| 6 |
+
AR_c: np.ndarray[Any, np.dtype[np.complex128]]
|
| 7 |
+
AR_m: np.ndarray[Any, np.dtype[np.timedelta64]]
|
| 8 |
+
AR_M: np.ndarray[Any, np.dtype[np.datetime64]]
|
| 9 |
+
|
| 10 |
+
AR_f > AR_m # E: Unsupported operand types
|
| 11 |
+
AR_c > AR_m # E: Unsupported operand types
|
| 12 |
+
|
| 13 |
+
AR_m > AR_f # E: Unsupported operand types
|
| 14 |
+
AR_m > AR_c # E: Unsupported operand types
|
| 15 |
+
|
| 16 |
+
AR_i > AR_M # E: Unsupported operand types
|
| 17 |
+
AR_f > AR_M # E: Unsupported operand types
|
| 18 |
+
AR_m > AR_M # E: Unsupported operand types
|
| 19 |
+
|
| 20 |
+
AR_M > AR_i # E: Unsupported operand types
|
| 21 |
+
AR_M > AR_f # E: Unsupported operand types
|
| 22 |
+
AR_M > AR_m # E: Unsupported operand types
|
| 23 |
+
|
| 24 |
+
AR_i > str() # E: No overload variant
|
| 25 |
+
AR_i > bytes() # E: No overload variant
|
| 26 |
+
str() > AR_M # E: Unsupported operand types
|
| 27 |
+
bytes() > AR_M # E: Unsupported operand types
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/constants.pyi
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
np.Inf = np.Inf # E: Cannot assign to final
|
| 4 |
+
np.ALLOW_THREADS = np.ALLOW_THREADS # E: Cannot assign to final
|
| 5 |
+
np.little_endian = np.little_endian # E: Cannot assign to final
|
| 6 |
+
np.UFUNC_PYVALS_NAME = "bob" # E: Incompatible types
|
| 7 |
+
np.CLIP = 2 # E: Incompatible types
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/datasource.pyi
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
path: Path
|
| 5 |
+
d1: np.DataSource
|
| 6 |
+
|
| 7 |
+
d1.abspath(path) # E: incompatible type
|
| 8 |
+
d1.abspath(b"...") # E: incompatible type
|
| 9 |
+
|
| 10 |
+
d1.exists(path) # E: incompatible type
|
| 11 |
+
d1.exists(b"...") # E: incompatible type
|
| 12 |
+
|
| 13 |
+
d1.open(path, "r") # E: incompatible type
|
| 14 |
+
d1.open(b"...", encoding="utf8") # E: incompatible type
|
| 15 |
+
d1.open(None, newline="/n") # E: incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/dtype.pyi
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class Test1:
|
| 5 |
+
not_dtype = np.dtype(float)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class Test2:
|
| 9 |
+
dtype = float
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
np.dtype(Test1()) # E: No overload variant of "dtype" matches
|
| 13 |
+
np.dtype(Test2()) # E: incompatible type
|
| 14 |
+
|
| 15 |
+
np.dtype( # E: No overload variant of "dtype" matches
|
| 16 |
+
{
|
| 17 |
+
"field1": (float, 1),
|
| 18 |
+
"field2": (int, 3),
|
| 19 |
+
}
|
| 20 |
+
)
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/einsumfunc.pyi
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
AR_i: np.ndarray[Any, np.dtype[np.int64]]
|
| 5 |
+
AR_f: np.ndarray[Any, np.dtype[np.float64]]
|
| 6 |
+
AR_m: np.ndarray[Any, np.dtype[np.timedelta64]]
|
| 7 |
+
AR_U: np.ndarray[Any, np.dtype[np.str_]]
|
| 8 |
+
|
| 9 |
+
np.einsum("i,i->i", AR_i, AR_m) # E: incompatible type
|
| 10 |
+
np.einsum("i,i->i", AR_f, AR_f, dtype=np.int32) # E: incompatible type
|
| 11 |
+
np.einsum("i,i->i", AR_i, AR_i, out=AR_U) # E: Value of type variable "_ArrayType" of "einsum" cannot be
|
| 12 |
+
np.einsum("i,i->i", AR_i, AR_i, out=AR_U, casting="unsafe") # E: No overload variant
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/false_positives.pyi
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import numpy.typing as npt
|
| 3 |
+
|
| 4 |
+
AR_f8: npt.NDArray[np.float64]
|
| 5 |
+
|
| 6 |
+
# NOTE: Mypy bug presumably due to the special-casing of heterogeneous tuples;
|
| 7 |
+
# xref numpy/numpy#20901
|
| 8 |
+
#
|
| 9 |
+
# The expected output should be no different than, e.g., when using a
|
| 10 |
+
# list instead of a tuple
|
| 11 |
+
np.concatenate(([1], AR_f8)) # E: Argument 1 to "concatenate" has incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/flatiter.pyi
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
from numpy._typing import _SupportsArray
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class Index:
|
| 8 |
+
def __index__(self) -> int:
|
| 9 |
+
...
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
a: "np.flatiter[np.ndarray]"
|
| 13 |
+
supports_array: _SupportsArray
|
| 14 |
+
|
| 15 |
+
a.base = Any # E: Property "base" defined in "flatiter" is read-only
|
| 16 |
+
a.coords = Any # E: Property "coords" defined in "flatiter" is read-only
|
| 17 |
+
a.index = Any # E: Property "index" defined in "flatiter" is read-only
|
| 18 |
+
a.copy(order='C') # E: Unexpected keyword argument
|
| 19 |
+
|
| 20 |
+
# NOTE: Contrary to `ndarray.__getitem__` its counterpart in `flatiter`
|
| 21 |
+
# does not accept objects with the `__array__` or `__index__` protocols;
|
| 22 |
+
# boolean indexing is just plain broken (gh-17175)
|
| 23 |
+
a[np.bool_()] # E: No overload variant of "__getitem__"
|
| 24 |
+
a[Index()] # E: No overload variant of "__getitem__"
|
| 25 |
+
a[supports_array] # E: No overload variant of "__getitem__"
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/fromnumeric.pyi
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for :mod:`numpy.core.fromnumeric`."""
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
import numpy.typing as npt
|
| 5 |
+
|
| 6 |
+
A = np.array(True, ndmin=2, dtype=bool)
|
| 7 |
+
A.setflags(write=False)
|
| 8 |
+
AR_U: npt.NDArray[np.str_]
|
| 9 |
+
|
| 10 |
+
a = np.bool_(True)
|
| 11 |
+
|
| 12 |
+
np.take(a, None) # E: No overload variant
|
| 13 |
+
np.take(a, axis=1.0) # E: No overload variant
|
| 14 |
+
np.take(A, out=1) # E: No overload variant
|
| 15 |
+
np.take(A, mode="bob") # E: No overload variant
|
| 16 |
+
|
| 17 |
+
np.reshape(a, None) # E: No overload variant
|
| 18 |
+
np.reshape(A, 1, order="bob") # E: No overload variant
|
| 19 |
+
|
| 20 |
+
np.choose(a, None) # E: No overload variant
|
| 21 |
+
np.choose(a, out=1.0) # E: No overload variant
|
| 22 |
+
np.choose(A, mode="bob") # E: No overload variant
|
| 23 |
+
|
| 24 |
+
np.repeat(a, None) # E: No overload variant
|
| 25 |
+
np.repeat(A, 1, axis=1.0) # E: No overload variant
|
| 26 |
+
|
| 27 |
+
np.swapaxes(A, None, 1) # E: No overload variant
|
| 28 |
+
np.swapaxes(A, 1, [0]) # E: No overload variant
|
| 29 |
+
|
| 30 |
+
np.transpose(A, axes=1.0) # E: No overload variant
|
| 31 |
+
|
| 32 |
+
np.partition(a, None) # E: No overload variant
|
| 33 |
+
np.partition( # E: No overload variant
|
| 34 |
+
a, 0, axis="bob"
|
| 35 |
+
)
|
| 36 |
+
np.partition( # E: No overload variant
|
| 37 |
+
A, 0, kind="bob"
|
| 38 |
+
)
|
| 39 |
+
np.partition(
|
| 40 |
+
A, 0, order=range(5) # E: Argument "order" to "partition" has incompatible type
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
np.argpartition(
|
| 44 |
+
a, None # E: incompatible type
|
| 45 |
+
)
|
| 46 |
+
np.argpartition(
|
| 47 |
+
a, 0, axis="bob" # E: incompatible type
|
| 48 |
+
)
|
| 49 |
+
np.argpartition(
|
| 50 |
+
A, 0, kind="bob" # E: incompatible type
|
| 51 |
+
)
|
| 52 |
+
np.argpartition(
|
| 53 |
+
A, 0, order=range(5) # E: Argument "order" to "argpartition" has incompatible type
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
np.sort(A, axis="bob") # E: No overload variant
|
| 57 |
+
np.sort(A, kind="bob") # E: No overload variant
|
| 58 |
+
np.sort(A, order=range(5)) # E: Argument "order" to "sort" has incompatible type
|
| 59 |
+
|
| 60 |
+
np.argsort(A, axis="bob") # E: Argument "axis" to "argsort" has incompatible type
|
| 61 |
+
np.argsort(A, kind="bob") # E: Argument "kind" to "argsort" has incompatible type
|
| 62 |
+
np.argsort(A, order=range(5)) # E: Argument "order" to "argsort" has incompatible type
|
| 63 |
+
|
| 64 |
+
np.argmax(A, axis="bob") # E: No overload variant of "argmax" matches argument type
|
| 65 |
+
np.argmax(A, kind="bob") # E: No overload variant of "argmax" matches argument type
|
| 66 |
+
|
| 67 |
+
np.argmin(A, axis="bob") # E: No overload variant of "argmin" matches argument type
|
| 68 |
+
np.argmin(A, kind="bob") # E: No overload variant of "argmin" matches argument type
|
| 69 |
+
|
| 70 |
+
np.searchsorted( # E: No overload variant of "searchsorted" matches argument type
|
| 71 |
+
A[0], 0, side="bob"
|
| 72 |
+
)
|
| 73 |
+
np.searchsorted( # E: No overload variant of "searchsorted" matches argument type
|
| 74 |
+
A[0], 0, sorter=1.0
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
np.resize(A, 1.0) # E: No overload variant
|
| 78 |
+
|
| 79 |
+
np.squeeze(A, 1.0) # E: No overload variant of "squeeze" matches argument type
|
| 80 |
+
|
| 81 |
+
np.diagonal(A, offset=None) # E: No overload variant
|
| 82 |
+
np.diagonal(A, axis1="bob") # E: No overload variant
|
| 83 |
+
np.diagonal(A, axis2=[]) # E: No overload variant
|
| 84 |
+
|
| 85 |
+
np.trace(A, offset=None) # E: No overload variant
|
| 86 |
+
np.trace(A, axis1="bob") # E: No overload variant
|
| 87 |
+
np.trace(A, axis2=[]) # E: No overload variant
|
| 88 |
+
|
| 89 |
+
np.ravel(a, order="bob") # E: No overload variant
|
| 90 |
+
|
| 91 |
+
np.compress( # E: No overload variant
|
| 92 |
+
[True], A, axis=1.0
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
np.clip(a, 1, 2, out=1) # E: No overload variant of "clip" matches argument type
|
| 96 |
+
|
| 97 |
+
np.sum(a, axis=1.0) # E: No overload variant
|
| 98 |
+
np.sum(a, keepdims=1.0) # E: No overload variant
|
| 99 |
+
np.sum(a, initial=[1]) # E: No overload variant
|
| 100 |
+
|
| 101 |
+
np.all(a, axis=1.0) # E: No overload variant
|
| 102 |
+
np.all(a, keepdims=1.0) # E: No overload variant
|
| 103 |
+
np.all(a, out=1.0) # E: No overload variant
|
| 104 |
+
|
| 105 |
+
np.any(a, axis=1.0) # E: No overload variant
|
| 106 |
+
np.any(a, keepdims=1.0) # E: No overload variant
|
| 107 |
+
np.any(a, out=1.0) # E: No overload variant
|
| 108 |
+
|
| 109 |
+
np.cumsum(a, axis=1.0) # E: No overload variant
|
| 110 |
+
np.cumsum(a, dtype=1.0) # E: No overload variant
|
| 111 |
+
np.cumsum(a, out=1.0) # E: No overload variant
|
| 112 |
+
|
| 113 |
+
np.ptp(a, axis=1.0) # E: No overload variant
|
| 114 |
+
np.ptp(a, keepdims=1.0) # E: No overload variant
|
| 115 |
+
np.ptp(a, out=1.0) # E: No overload variant
|
| 116 |
+
|
| 117 |
+
np.amax(a, axis=1.0) # E: No overload variant
|
| 118 |
+
np.amax(a, keepdims=1.0) # E: No overload variant
|
| 119 |
+
np.amax(a, out=1.0) # E: No overload variant
|
| 120 |
+
np.amax(a, initial=[1.0]) # E: No overload variant
|
| 121 |
+
np.amax(a, where=[1.0]) # E: incompatible type
|
| 122 |
+
|
| 123 |
+
np.amin(a, axis=1.0) # E: No overload variant
|
| 124 |
+
np.amin(a, keepdims=1.0) # E: No overload variant
|
| 125 |
+
np.amin(a, out=1.0) # E: No overload variant
|
| 126 |
+
np.amin(a, initial=[1.0]) # E: No overload variant
|
| 127 |
+
np.amin(a, where=[1.0]) # E: incompatible type
|
| 128 |
+
|
| 129 |
+
np.prod(a, axis=1.0) # E: No overload variant
|
| 130 |
+
np.prod(a, out=False) # E: No overload variant
|
| 131 |
+
np.prod(a, keepdims=1.0) # E: No overload variant
|
| 132 |
+
np.prod(a, initial=int) # E: No overload variant
|
| 133 |
+
np.prod(a, where=1.0) # E: No overload variant
|
| 134 |
+
np.prod(AR_U) # E: incompatible type
|
| 135 |
+
|
| 136 |
+
np.cumprod(a, axis=1.0) # E: No overload variant
|
| 137 |
+
np.cumprod(a, out=False) # E: No overload variant
|
| 138 |
+
np.cumprod(AR_U) # E: incompatible type
|
| 139 |
+
|
| 140 |
+
np.size(a, axis=1.0) # E: Argument "axis" to "size" has incompatible type
|
| 141 |
+
|
| 142 |
+
np.around(a, decimals=1.0) # E: No overload variant
|
| 143 |
+
np.around(a, out=type) # E: No overload variant
|
| 144 |
+
np.around(AR_U) # E: incompatible type
|
| 145 |
+
|
| 146 |
+
np.mean(a, axis=1.0) # E: No overload variant
|
| 147 |
+
np.mean(a, out=False) # E: No overload variant
|
| 148 |
+
np.mean(a, keepdims=1.0) # E: No overload variant
|
| 149 |
+
np.mean(AR_U) # E: incompatible type
|
| 150 |
+
|
| 151 |
+
np.std(a, axis=1.0) # E: No overload variant
|
| 152 |
+
np.std(a, out=False) # E: No overload variant
|
| 153 |
+
np.std(a, ddof='test') # E: No overload variant
|
| 154 |
+
np.std(a, keepdims=1.0) # E: No overload variant
|
| 155 |
+
np.std(AR_U) # E: incompatible type
|
| 156 |
+
|
| 157 |
+
np.var(a, axis=1.0) # E: No overload variant
|
| 158 |
+
np.var(a, out=False) # E: No overload variant
|
| 159 |
+
np.var(a, ddof='test') # E: No overload variant
|
| 160 |
+
np.var(a, keepdims=1.0) # E: No overload variant
|
| 161 |
+
np.var(AR_U) # E: incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/histograms.pyi
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import numpy.typing as npt
|
| 3 |
+
|
| 4 |
+
AR_i8: npt.NDArray[np.int64]
|
| 5 |
+
AR_f8: npt.NDArray[np.float64]
|
| 6 |
+
|
| 7 |
+
np.histogram_bin_edges(AR_i8, range=(0, 1, 2)) # E: incompatible type
|
| 8 |
+
|
| 9 |
+
np.histogram(AR_i8, range=(0, 1, 2)) # E: incompatible type
|
| 10 |
+
|
| 11 |
+
np.histogramdd(AR_i8, range=(0, 1)) # E: incompatible type
|
| 12 |
+
np.histogramdd(AR_i8, range=[(0, 1, 2)]) # E: incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/index_tricks.pyi
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
AR_LIKE_i: list[int]
|
| 4 |
+
AR_LIKE_f: list[float]
|
| 5 |
+
|
| 6 |
+
np.ndindex([1, 2, 3]) # E: No overload variant
|
| 7 |
+
np.unravel_index(AR_LIKE_f, (1, 2, 3)) # E: incompatible type
|
| 8 |
+
np.ravel_multi_index(AR_LIKE_i, (1, 2, 3), mode="bob") # E: No overload variant
|
| 9 |
+
np.mgrid[1] # E: Invalid index type
|
| 10 |
+
np.mgrid[...] # E: Invalid index type
|
| 11 |
+
np.ogrid[1] # E: Invalid index type
|
| 12 |
+
np.ogrid[...] # E: Invalid index type
|
| 13 |
+
np.fill_diagonal(AR_LIKE_f, 2) # E: incompatible type
|
| 14 |
+
np.diag_indices(1.0) # E: incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/lib_function_base.pyi
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
import numpy.typing as npt
|
| 5 |
+
|
| 6 |
+
AR_f8: npt.NDArray[np.float64]
|
| 7 |
+
AR_c16: npt.NDArray[np.complex128]
|
| 8 |
+
AR_m: npt.NDArray[np.timedelta64]
|
| 9 |
+
AR_M: npt.NDArray[np.datetime64]
|
| 10 |
+
AR_O: npt.NDArray[np.object_]
|
| 11 |
+
|
| 12 |
+
def func(a: int) -> None: ...
|
| 13 |
+
|
| 14 |
+
np.average(AR_m) # E: incompatible type
|
| 15 |
+
np.select(1, [AR_f8]) # E: incompatible type
|
| 16 |
+
np.angle(AR_m) # E: incompatible type
|
| 17 |
+
np.unwrap(AR_m) # E: incompatible type
|
| 18 |
+
np.unwrap(AR_c16) # E: incompatible type
|
| 19 |
+
np.trim_zeros(1) # E: incompatible type
|
| 20 |
+
np.place(1, [True], 1.5) # E: incompatible type
|
| 21 |
+
np.vectorize(1) # E: incompatible type
|
| 22 |
+
np.add_newdoc("__main__", 1.5, "docstring") # E: incompatible type
|
| 23 |
+
np.place(AR_f8, slice(None), 5) # E: incompatible type
|
| 24 |
+
|
| 25 |
+
np.interp(AR_f8, AR_c16, AR_f8) # E: incompatible type
|
| 26 |
+
np.interp(AR_c16, AR_f8, AR_f8) # E: incompatible type
|
| 27 |
+
np.interp(AR_f8, AR_f8, AR_f8, period=AR_c16) # E: No overload variant
|
| 28 |
+
np.interp(AR_f8, AR_f8, AR_O) # E: incompatible type
|
| 29 |
+
|
| 30 |
+
np.cov(AR_m) # E: incompatible type
|
| 31 |
+
np.cov(AR_O) # E: incompatible type
|
| 32 |
+
np.corrcoef(AR_m) # E: incompatible type
|
| 33 |
+
np.corrcoef(AR_O) # E: incompatible type
|
| 34 |
+
np.corrcoef(AR_f8, bias=True) # E: No overload variant
|
| 35 |
+
np.corrcoef(AR_f8, ddof=2) # E: No overload variant
|
| 36 |
+
np.blackman(1j) # E: incompatible type
|
| 37 |
+
np.bartlett(1j) # E: incompatible type
|
| 38 |
+
np.hanning(1j) # E: incompatible type
|
| 39 |
+
np.hamming(1j) # E: incompatible type
|
| 40 |
+
np.hamming(AR_c16) # E: incompatible type
|
| 41 |
+
np.kaiser(1j, 1) # E: incompatible type
|
| 42 |
+
np.sinc(AR_O) # E: incompatible type
|
| 43 |
+
np.median(AR_M) # E: incompatible type
|
| 44 |
+
|
| 45 |
+
np.add_newdoc_ufunc(func, "docstring") # E: incompatible type
|
| 46 |
+
np.percentile(AR_f8, 50j) # E: No overload variant
|
| 47 |
+
np.percentile(AR_f8, 50, interpolation="bob") # E: No overload variant
|
| 48 |
+
np.quantile(AR_f8, 0.5j) # E: No overload variant
|
| 49 |
+
np.quantile(AR_f8, 0.5, interpolation="bob") # E: No overload variant
|
| 50 |
+
np.meshgrid(AR_f8, AR_f8, indexing="bob") # E: incompatible type
|
| 51 |
+
np.delete(AR_f8, AR_f8) # E: incompatible type
|
| 52 |
+
np.insert(AR_f8, AR_f8, 1.5) # E: incompatible type
|
| 53 |
+
np.digitize(AR_f8, 1j) # E: No overload variant
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/lib_polynomial.pyi
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import numpy.typing as npt
|
| 3 |
+
|
| 4 |
+
AR_f8: npt.NDArray[np.float64]
|
| 5 |
+
AR_c16: npt.NDArray[np.complex128]
|
| 6 |
+
AR_O: npt.NDArray[np.object_]
|
| 7 |
+
AR_U: npt.NDArray[np.str_]
|
| 8 |
+
|
| 9 |
+
poly_obj: np.poly1d
|
| 10 |
+
|
| 11 |
+
np.polymul(AR_f8, AR_U) # E: incompatible type
|
| 12 |
+
np.polydiv(AR_f8, AR_U) # E: incompatible type
|
| 13 |
+
|
| 14 |
+
5**poly_obj # E: No overload variant
|
| 15 |
+
|
| 16 |
+
np.polyint(AR_U) # E: incompatible type
|
| 17 |
+
np.polyint(AR_f8, m=1j) # E: No overload variant
|
| 18 |
+
|
| 19 |
+
np.polyder(AR_U) # E: incompatible type
|
| 20 |
+
np.polyder(AR_f8, m=1j) # E: No overload variant
|
| 21 |
+
|
| 22 |
+
np.polyfit(AR_O, AR_f8, 1) # E: incompatible type
|
| 23 |
+
np.polyfit(AR_f8, AR_f8, 1, rcond=1j) # E: No overload variant
|
| 24 |
+
np.polyfit(AR_f8, AR_f8, 1, w=AR_c16) # E: incompatible type
|
| 25 |
+
np.polyfit(AR_f8, AR_f8, 1, cov="bob") # E: No overload variant
|
| 26 |
+
|
| 27 |
+
np.polyval(AR_f8, AR_U) # E: incompatible type
|
| 28 |
+
np.polyadd(AR_f8, AR_U) # E: incompatible type
|
| 29 |
+
np.polysub(AR_f8, AR_U) # E: incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/lib_utils.pyi
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
np.deprecate(1) # E: No overload variant
|
| 4 |
+
|
| 5 |
+
np.deprecate_with_doc(1) # E: incompatible type
|
| 6 |
+
|
| 7 |
+
np.byte_bounds(1) # E: incompatible type
|
| 8 |
+
|
| 9 |
+
np.who(1) # E: incompatible type
|
| 10 |
+
|
| 11 |
+
np.lookfor(None) # E: incompatible type
|
| 12 |
+
|
| 13 |
+
np.safe_eval(None) # E: incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/lib_version.pyi
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from numpy.lib import NumpyVersion
|
| 2 |
+
|
| 3 |
+
version: NumpyVersion
|
| 4 |
+
|
| 5 |
+
NumpyVersion(b"1.8.0") # E: incompatible type
|
| 6 |
+
version >= b"1.8.0" # E: Unsupported operand types
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/linalg.pyi
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import numpy.typing as npt
|
| 3 |
+
|
| 4 |
+
AR_f8: npt.NDArray[np.float64]
|
| 5 |
+
AR_O: npt.NDArray[np.object_]
|
| 6 |
+
AR_M: npt.NDArray[np.datetime64]
|
| 7 |
+
|
| 8 |
+
np.linalg.tensorsolve(AR_O, AR_O) # E: incompatible type
|
| 9 |
+
|
| 10 |
+
np.linalg.solve(AR_O, AR_O) # E: incompatible type
|
| 11 |
+
|
| 12 |
+
np.linalg.tensorinv(AR_O) # E: incompatible type
|
| 13 |
+
|
| 14 |
+
np.linalg.inv(AR_O) # E: incompatible type
|
| 15 |
+
|
| 16 |
+
np.linalg.matrix_power(AR_M, 5) # E: incompatible type
|
| 17 |
+
|
| 18 |
+
np.linalg.cholesky(AR_O) # E: incompatible type
|
| 19 |
+
|
| 20 |
+
np.linalg.qr(AR_O) # E: incompatible type
|
| 21 |
+
np.linalg.qr(AR_f8, mode="bob") # E: No overload variant
|
| 22 |
+
|
| 23 |
+
np.linalg.eigvals(AR_O) # E: incompatible type
|
| 24 |
+
|
| 25 |
+
np.linalg.eigvalsh(AR_O) # E: incompatible type
|
| 26 |
+
np.linalg.eigvalsh(AR_O, UPLO="bob") # E: No overload variant
|
| 27 |
+
|
| 28 |
+
np.linalg.eig(AR_O) # E: incompatible type
|
| 29 |
+
|
| 30 |
+
np.linalg.eigh(AR_O) # E: incompatible type
|
| 31 |
+
np.linalg.eigh(AR_O, UPLO="bob") # E: No overload variant
|
| 32 |
+
|
| 33 |
+
np.linalg.svd(AR_O) # E: incompatible type
|
| 34 |
+
|
| 35 |
+
np.linalg.cond(AR_O) # E: incompatible type
|
| 36 |
+
np.linalg.cond(AR_f8, p="bob") # E: incompatible type
|
| 37 |
+
|
| 38 |
+
np.linalg.matrix_rank(AR_O) # E: incompatible type
|
| 39 |
+
|
| 40 |
+
np.linalg.pinv(AR_O) # E: incompatible type
|
| 41 |
+
|
| 42 |
+
np.linalg.slogdet(AR_O) # E: incompatible type
|
| 43 |
+
|
| 44 |
+
np.linalg.det(AR_O) # E: incompatible type
|
| 45 |
+
|
| 46 |
+
np.linalg.norm(AR_f8, ord="bob") # E: No overload variant
|
| 47 |
+
|
| 48 |
+
np.linalg.multi_dot([AR_M]) # E: incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/memmap.pyi
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
with open("file.txt", "r") as f:
|
| 4 |
+
np.memmap(f) # E: No overload variant
|
| 5 |
+
np.memmap("test.txt", shape=[10, 5]) # E: No overload variant
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/modules.pyi
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
np.testing.bob # E: Module has no attribute
|
| 4 |
+
np.bob # E: Module has no attribute
|
| 5 |
+
|
| 6 |
+
# Stdlib modules in the namespace by accident
|
| 7 |
+
np.warnings # E: Module has no attribute
|
| 8 |
+
np.sys # E: Module has no attribute
|
| 9 |
+
np.os # E: Module "numpy" does not explicitly export
|
| 10 |
+
np.math # E: Module has no attribute
|
| 11 |
+
|
| 12 |
+
# Public sub-modules that are not imported to their parent module by default;
|
| 13 |
+
# e.g. one must first execute `import numpy.lib.recfunctions`
|
| 14 |
+
np.lib.recfunctions # E: Module has no attribute
|
| 15 |
+
|
| 16 |
+
np.__NUMPY_SETUP__ # E: Module has no attribute
|
| 17 |
+
np.__deprecated_attrs__ # E: Module has no attribute
|
| 18 |
+
np.__expired_functions__ # E: Module has no attribute
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/multiarray.pyi
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import numpy.typing as npt
|
| 3 |
+
|
| 4 |
+
i8: np.int64
|
| 5 |
+
|
| 6 |
+
AR_b: npt.NDArray[np.bool_]
|
| 7 |
+
AR_u1: npt.NDArray[np.uint8]
|
| 8 |
+
AR_i8: npt.NDArray[np.int64]
|
| 9 |
+
AR_f8: npt.NDArray[np.float64]
|
| 10 |
+
AR_M: npt.NDArray[np.datetime64]
|
| 11 |
+
|
| 12 |
+
M: np.datetime64
|
| 13 |
+
|
| 14 |
+
AR_LIKE_f: list[float]
|
| 15 |
+
|
| 16 |
+
def func(a: int) -> None: ...
|
| 17 |
+
|
| 18 |
+
np.where(AR_b, 1) # E: No overload variant
|
| 19 |
+
|
| 20 |
+
np.can_cast(AR_f8, 1) # E: incompatible type
|
| 21 |
+
|
| 22 |
+
np.vdot(AR_M, AR_M) # E: incompatible type
|
| 23 |
+
|
| 24 |
+
np.copyto(AR_LIKE_f, AR_f8) # E: incompatible type
|
| 25 |
+
|
| 26 |
+
np.putmask(AR_LIKE_f, [True, True, False], 1.5) # E: incompatible type
|
| 27 |
+
|
| 28 |
+
np.packbits(AR_f8) # E: incompatible type
|
| 29 |
+
np.packbits(AR_u1, bitorder=">") # E: incompatible type
|
| 30 |
+
|
| 31 |
+
np.unpackbits(AR_i8) # E: incompatible type
|
| 32 |
+
np.unpackbits(AR_u1, bitorder=">") # E: incompatible type
|
| 33 |
+
|
| 34 |
+
np.shares_memory(1, 1, max_work=i8) # E: incompatible type
|
| 35 |
+
np.may_share_memory(1, 1, max_work=i8) # E: incompatible type
|
| 36 |
+
|
| 37 |
+
np.arange(M) # E: No overload variant
|
| 38 |
+
np.arange(stop=10) # E: No overload variant
|
| 39 |
+
|
| 40 |
+
np.datetime_data(int) # E: incompatible type
|
| 41 |
+
|
| 42 |
+
np.busday_offset("2012", 10) # E: No overload variant
|
| 43 |
+
|
| 44 |
+
np.datetime_as_string("2012") # E: No overload variant
|
| 45 |
+
|
| 46 |
+
np.compare_chararrays("a", b"a", "==", False) # E: No overload variant
|
| 47 |
+
|
| 48 |
+
np.add_docstring(func, None) # E: incompatible type
|
| 49 |
+
|
| 50 |
+
np.nested_iters([AR_i8, AR_i8]) # E: Missing positional argument
|
| 51 |
+
np.nested_iters([AR_i8, AR_i8], 0) # E: incompatible type
|
| 52 |
+
np.nested_iters([AR_i8, AR_i8], [0]) # E: incompatible type
|
| 53 |
+
np.nested_iters([AR_i8, AR_i8], [[0], [1]], flags=["test"]) # E: incompatible type
|
| 54 |
+
np.nested_iters([AR_i8, AR_i8], [[0], [1]], op_flags=[["test"]]) # E: incompatible type
|
| 55 |
+
np.nested_iters([AR_i8, AR_i8], [[0], [1]], buffersize=1.0) # E: incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/ndarray.pyi
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
# Ban setting dtype since mutating the type of the array in place
|
| 4 |
+
# makes having ndarray be generic over dtype impossible. Generally
|
| 5 |
+
# users should use `ndarray.view` in this situation anyway. See
|
| 6 |
+
#
|
| 7 |
+
# https://github.com/numpy/numpy-stubs/issues/7
|
| 8 |
+
#
|
| 9 |
+
# for more context.
|
| 10 |
+
float_array = np.array([1.0])
|
| 11 |
+
float_array.dtype = np.bool_ # E: Property "dtype" defined in "ndarray" is read-only
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/ndarray_misc.pyi
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Tests for miscellaneous (non-magic) ``np.ndarray``/``np.generic`` methods.
|
| 3 |
+
|
| 4 |
+
More extensive tests are performed for the methods'
|
| 5 |
+
function-based counterpart in `../from_numeric.py`.
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from typing import Any
|
| 10 |
+
import numpy as np
|
| 11 |
+
|
| 12 |
+
f8: np.float64
|
| 13 |
+
AR_f8: np.ndarray[Any, np.dtype[np.float64]]
|
| 14 |
+
AR_M: np.ndarray[Any, np.dtype[np.datetime64]]
|
| 15 |
+
AR_b: np.ndarray[Any, np.dtype[np.bool_]]
|
| 16 |
+
|
| 17 |
+
ctypes_obj = AR_f8.ctypes
|
| 18 |
+
|
| 19 |
+
reveal_type(ctypes_obj.get_data()) # E: has no attribute
|
| 20 |
+
reveal_type(ctypes_obj.get_shape()) # E: has no attribute
|
| 21 |
+
reveal_type(ctypes_obj.get_strides()) # E: has no attribute
|
| 22 |
+
reveal_type(ctypes_obj.get_as_parameter()) # E: has no attribute
|
| 23 |
+
|
| 24 |
+
f8.argpartition(0) # E: has no attribute
|
| 25 |
+
f8.diagonal() # E: has no attribute
|
| 26 |
+
f8.dot(1) # E: has no attribute
|
| 27 |
+
f8.nonzero() # E: has no attribute
|
| 28 |
+
f8.partition(0) # E: has no attribute
|
| 29 |
+
f8.put(0, 2) # E: has no attribute
|
| 30 |
+
f8.setfield(2, np.float64) # E: has no attribute
|
| 31 |
+
f8.sort() # E: has no attribute
|
| 32 |
+
f8.trace() # E: has no attribute
|
| 33 |
+
|
| 34 |
+
AR_M.__int__() # E: Invalid self argument
|
| 35 |
+
AR_M.__float__() # E: Invalid self argument
|
| 36 |
+
AR_M.__complex__() # E: Invalid self argument
|
| 37 |
+
AR_b.__index__() # E: Invalid self argument
|
| 38 |
+
|
| 39 |
+
AR_f8[1.5] # E: No overload variant
|
| 40 |
+
AR_f8["field_a"] # E: No overload variant
|
| 41 |
+
AR_f8[["field_a", "field_b"]] # E: Invalid index type
|
| 42 |
+
|
| 43 |
+
AR_f8.__array_finalize__(object()) # E: incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/nditer.pyi
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
class Test(np.nditer): ... # E: Cannot inherit from final class
|
| 4 |
+
|
| 5 |
+
np.nditer([0, 1], flags=["test"]) # E: incompatible type
|
| 6 |
+
np.nditer([0, 1], op_flags=[["test"]]) # E: incompatible type
|
| 7 |
+
np.nditer([0, 1], itershape=(1.0,)) # E: incompatible type
|
| 8 |
+
np.nditer([0, 1], buffersize=1.0) # E: incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/nested_sequence.pyi
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Sequence
|
| 2 |
+
from numpy._typing import _NestedSequence
|
| 3 |
+
|
| 4 |
+
a: Sequence[float]
|
| 5 |
+
b: list[complex]
|
| 6 |
+
c: tuple[str, ...]
|
| 7 |
+
d: int
|
| 8 |
+
e: str
|
| 9 |
+
|
| 10 |
+
def func(a: _NestedSequence[int]) -> None:
|
| 11 |
+
...
|
| 12 |
+
|
| 13 |
+
reveal_type(func(a)) # E: incompatible type
|
| 14 |
+
reveal_type(func(b)) # E: incompatible type
|
| 15 |
+
reveal_type(func(c)) # E: incompatible type
|
| 16 |
+
reveal_type(func(d)) # E: incompatible type
|
| 17 |
+
reveal_type(func(e)) # E: incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/npyio.pyi
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pathlib
|
| 2 |
+
from typing import IO
|
| 3 |
+
|
| 4 |
+
import numpy.typing as npt
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
str_path: str
|
| 8 |
+
bytes_path: bytes
|
| 9 |
+
pathlib_path: pathlib.Path
|
| 10 |
+
str_file: IO[str]
|
| 11 |
+
AR_i8: npt.NDArray[np.int64]
|
| 12 |
+
|
| 13 |
+
np.load(str_file) # E: incompatible type
|
| 14 |
+
|
| 15 |
+
np.save(bytes_path, AR_i8) # E: incompatible type
|
| 16 |
+
|
| 17 |
+
np.savez(bytes_path, AR_i8) # E: incompatible type
|
| 18 |
+
|
| 19 |
+
np.savez_compressed(bytes_path, AR_i8) # E: incompatible type
|
| 20 |
+
|
| 21 |
+
np.loadtxt(bytes_path) # E: incompatible type
|
| 22 |
+
|
| 23 |
+
np.fromregex(bytes_path, ".", np.int64) # E: No overload variant
|
| 24 |
+
|
| 25 |
+
np.recfromtxt(bytes_path) # E: incompatible type
|
| 26 |
+
|
| 27 |
+
np.recfromcsv(bytes_path) # E: incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/numerictypes.pyi
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
# Technically this works, but probably shouldn't. See
|
| 4 |
+
#
|
| 5 |
+
# https://github.com/numpy/numpy/issues/16366
|
| 6 |
+
#
|
| 7 |
+
np.maximum_sctype(1) # E: No overload variant
|
| 8 |
+
|
| 9 |
+
np.issubsctype(1, np.int64) # E: incompatible type
|
| 10 |
+
|
| 11 |
+
np.issubdtype(1, np.int64) # E: incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/random.pyi
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from typing import Any
|
| 3 |
+
|
| 4 |
+
SEED_FLOAT: float = 457.3
|
| 5 |
+
SEED_ARR_FLOAT: np.ndarray[Any, np.dtype[np.float64]] = np.array([1.0, 2, 3, 4])
|
| 6 |
+
SEED_ARRLIKE_FLOAT: list[float] = [1.0, 2.0, 3.0, 4.0]
|
| 7 |
+
SEED_SEED_SEQ: np.random.SeedSequence = np.random.SeedSequence(0)
|
| 8 |
+
SEED_STR: str = "String seeding not allowed"
|
| 9 |
+
# default rng
|
| 10 |
+
np.random.default_rng(SEED_FLOAT) # E: incompatible type
|
| 11 |
+
np.random.default_rng(SEED_ARR_FLOAT) # E: incompatible type
|
| 12 |
+
np.random.default_rng(SEED_ARRLIKE_FLOAT) # E: incompatible type
|
| 13 |
+
np.random.default_rng(SEED_STR) # E: incompatible type
|
| 14 |
+
|
| 15 |
+
# Seed Sequence
|
| 16 |
+
np.random.SeedSequence(SEED_FLOAT) # E: incompatible type
|
| 17 |
+
np.random.SeedSequence(SEED_ARR_FLOAT) # E: incompatible type
|
| 18 |
+
np.random.SeedSequence(SEED_ARRLIKE_FLOAT) # E: incompatible type
|
| 19 |
+
np.random.SeedSequence(SEED_SEED_SEQ) # E: incompatible type
|
| 20 |
+
np.random.SeedSequence(SEED_STR) # E: incompatible type
|
| 21 |
+
|
| 22 |
+
seed_seq: np.random.bit_generator.SeedSequence = np.random.SeedSequence()
|
| 23 |
+
seed_seq.spawn(11.5) # E: incompatible type
|
| 24 |
+
seed_seq.generate_state(3.14) # E: incompatible type
|
| 25 |
+
seed_seq.generate_state(3, np.uint8) # E: incompatible type
|
| 26 |
+
seed_seq.generate_state(3, "uint8") # E: incompatible type
|
| 27 |
+
seed_seq.generate_state(3, "u1") # E: incompatible type
|
| 28 |
+
seed_seq.generate_state(3, np.uint16) # E: incompatible type
|
| 29 |
+
seed_seq.generate_state(3, "uint16") # E: incompatible type
|
| 30 |
+
seed_seq.generate_state(3, "u2") # E: incompatible type
|
| 31 |
+
seed_seq.generate_state(3, np.int32) # E: incompatible type
|
| 32 |
+
seed_seq.generate_state(3, "int32") # E: incompatible type
|
| 33 |
+
seed_seq.generate_state(3, "i4") # E: incompatible type
|
| 34 |
+
|
| 35 |
+
# Bit Generators
|
| 36 |
+
np.random.MT19937(SEED_FLOAT) # E: incompatible type
|
| 37 |
+
np.random.MT19937(SEED_ARR_FLOAT) # E: incompatible type
|
| 38 |
+
np.random.MT19937(SEED_ARRLIKE_FLOAT) # E: incompatible type
|
| 39 |
+
np.random.MT19937(SEED_STR) # E: incompatible type
|
| 40 |
+
|
| 41 |
+
np.random.PCG64(SEED_FLOAT) # E: incompatible type
|
| 42 |
+
np.random.PCG64(SEED_ARR_FLOAT) # E: incompatible type
|
| 43 |
+
np.random.PCG64(SEED_ARRLIKE_FLOAT) # E: incompatible type
|
| 44 |
+
np.random.PCG64(SEED_STR) # E: incompatible type
|
| 45 |
+
|
| 46 |
+
np.random.Philox(SEED_FLOAT) # E: incompatible type
|
| 47 |
+
np.random.Philox(SEED_ARR_FLOAT) # E: incompatible type
|
| 48 |
+
np.random.Philox(SEED_ARRLIKE_FLOAT) # E: incompatible type
|
| 49 |
+
np.random.Philox(SEED_STR) # E: incompatible type
|
| 50 |
+
|
| 51 |
+
np.random.SFC64(SEED_FLOAT) # E: incompatible type
|
| 52 |
+
np.random.SFC64(SEED_ARR_FLOAT) # E: incompatible type
|
| 53 |
+
np.random.SFC64(SEED_ARRLIKE_FLOAT) # E: incompatible type
|
| 54 |
+
np.random.SFC64(SEED_STR) # E: incompatible type
|
| 55 |
+
|
| 56 |
+
# Generator
|
| 57 |
+
np.random.Generator(None) # E: incompatible type
|
| 58 |
+
np.random.Generator(12333283902830213) # E: incompatible type
|
| 59 |
+
np.random.Generator("OxFEEDF00D") # E: incompatible type
|
| 60 |
+
np.random.Generator([123, 234]) # E: incompatible type
|
| 61 |
+
np.random.Generator(np.array([123, 234], dtype="u4")) # E: incompatible type
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/rec.pyi
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import numpy.typing as npt
|
| 3 |
+
|
| 4 |
+
AR_i8: npt.NDArray[np.int64]
|
| 5 |
+
|
| 6 |
+
np.rec.fromarrays(1) # E: No overload variant
|
| 7 |
+
np.rec.fromarrays([1, 2, 3], dtype=[("f8", "f8")], formats=["f8", "f8"]) # E: No overload variant
|
| 8 |
+
|
| 9 |
+
np.rec.fromrecords(AR_i8) # E: incompatible type
|
| 10 |
+
np.rec.fromrecords([(1.5,)], dtype=[("f8", "f8")], formats=["f8", "f8"]) # E: No overload variant
|
| 11 |
+
|
| 12 |
+
np.rec.fromstring("string", dtype=[("f8", "f8")]) # E: No overload variant
|
| 13 |
+
np.rec.fromstring(b"bytes") # E: No overload variant
|
| 14 |
+
np.rec.fromstring(b"(1.5,)", dtype=[("f8", "f8")], formats=["f8", "f8"]) # E: No overload variant
|
| 15 |
+
|
| 16 |
+
with open("test", "r") as f:
|
| 17 |
+
np.rec.fromfile(f, dtype=[("f8", "f8")]) # E: No overload variant
|
.venv/lib/python3.11/site-packages/numpy/typing/tests/data/fail/scalars.pyi
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
f2: np.float16
|
| 5 |
+
f8: np.float64
|
| 6 |
+
c8: np.complex64
|
| 7 |
+
|
| 8 |
+
# Construction
|
| 9 |
+
|
| 10 |
+
np.float32(3j) # E: incompatible type
|
| 11 |
+
|
| 12 |
+
# Technically the following examples are valid NumPy code. But they
|
| 13 |
+
# are not considered a best practice, and people who wish to use the
|
| 14 |
+
# stubs should instead do
|
| 15 |
+
#
|
| 16 |
+
# np.array([1.0, 0.0, 0.0], dtype=np.float32)
|
| 17 |
+
# np.array([], dtype=np.complex64)
|
| 18 |
+
#
|
| 19 |
+
# See e.g. the discussion on the mailing list
|
| 20 |
+
#
|
| 21 |
+
# https://mail.python.org/pipermail/numpy-discussion/2020-April/080566.html
|
| 22 |
+
#
|
| 23 |
+
# and the issue
|
| 24 |
+
#
|
| 25 |
+
# https://github.com/numpy/numpy-stubs/issues/41
|
| 26 |
+
#
|
| 27 |
+
# for more context.
|
| 28 |
+
np.float32([1.0, 0.0, 0.0]) # E: incompatible type
|
| 29 |
+
np.complex64([]) # E: incompatible type
|
| 30 |
+
|
| 31 |
+
np.complex64(1, 2) # E: Too many arguments
|
| 32 |
+
# TODO: protocols (can't check for non-existent protocols w/ __getattr__)
|
| 33 |
+
|
| 34 |
+
np.datetime64(0) # E: No overload variant
|
| 35 |
+
|
| 36 |
+
class A:
|
| 37 |
+
def __float__(self):
|
| 38 |
+
return 1.0
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
np.int8(A()) # E: incompatible type
|
| 42 |
+
np.int16(A()) # E: incompatible type
|
| 43 |
+
np.int32(A()) # E: incompatible type
|
| 44 |
+
np.int64(A()) # E: incompatible type
|
| 45 |
+
np.uint8(A()) # E: incompatible type
|
| 46 |
+
np.uint16(A()) # E: incompatible type
|
| 47 |
+
np.uint32(A()) # E: incompatible type
|
| 48 |
+
np.uint64(A()) # E: incompatible type
|
| 49 |
+
|
| 50 |
+
np.void("test") # E: No overload variant
|
| 51 |
+
np.void("test", dtype=None) # E: No overload variant
|
| 52 |
+
|
| 53 |
+
np.generic(1) # E: Cannot instantiate abstract class
|
| 54 |
+
np.number(1) # E: Cannot instantiate abstract class
|
| 55 |
+
np.integer(1) # E: Cannot instantiate abstract class
|
| 56 |
+
np.inexact(1) # E: Cannot instantiate abstract class
|
| 57 |
+
np.character("test") # E: Cannot instantiate abstract class
|
| 58 |
+
np.flexible(b"test") # E: Cannot instantiate abstract class
|
| 59 |
+
|
| 60 |
+
np.float64(value=0.0) # E: Unexpected keyword argument
|
| 61 |
+
np.int64(value=0) # E: Unexpected keyword argument
|
| 62 |
+
np.uint64(value=0) # E: Unexpected keyword argument
|
| 63 |
+
np.complex128(value=0.0j) # E: Unexpected keyword argument
|
| 64 |
+
np.str_(value='bob') # E: No overload variant
|
| 65 |
+
np.bytes_(value=b'test') # E: No overload variant
|
| 66 |
+
np.void(value=b'test') # E: No overload variant
|
| 67 |
+
np.bool_(value=True) # E: Unexpected keyword argument
|
| 68 |
+
np.datetime64(value="2019") # E: No overload variant
|
| 69 |
+
np.timedelta64(value=0) # E: Unexpected keyword argument
|
| 70 |
+
|
| 71 |
+
np.bytes_(b"hello", encoding='utf-8') # E: No overload variant
|
| 72 |
+
np.str_("hello", encoding='utf-8') # E: No overload variant
|
| 73 |
+
|
| 74 |
+
f8.item(1) # E: incompatible type
|
| 75 |
+
f8.item((0, 1)) # E: incompatible type
|
| 76 |
+
f8.squeeze(axis=1) # E: incompatible type
|
| 77 |
+
f8.squeeze(axis=(0, 1)) # E: incompatible type
|
| 78 |
+
f8.transpose(1) # E: incompatible type
|
| 79 |
+
|
| 80 |
+
def func(a: np.float32) -> None: ...
|
| 81 |
+
|
| 82 |
+
func(f2) # E: incompatible type
|
| 83 |
+
func(f8) # E: incompatible type
|
| 84 |
+
|
| 85 |
+
round(c8) # E: No overload variant
|
| 86 |
+
|
| 87 |
+
c8.__getnewargs__() # E: Invalid self argument
|
| 88 |
+
f2.__getnewargs__() # E: Invalid self argument
|
| 89 |
+
f2.hex() # E: Invalid self argument
|
| 90 |
+
np.float16.fromhex("0x0.0p+0") # E: Invalid self argument
|
| 91 |
+
f2.__trunc__() # E: Invalid self argument
|
| 92 |
+
f2.__getformat__("float") # E: Invalid self argument
|