forked from Alsan/Post_finder
venv
This commit is contained in:
175
venv/lib/python3.12/site-packages/numpy/typing/__init__.py
Normal file
175
venv/lib/python3.12/site-packages/numpy/typing/__init__.py
Normal file
@ -0,0 +1,175 @@
|
||||
"""
|
||||
============================
|
||||
Typing (:mod:`numpy.typing`)
|
||||
============================
|
||||
|
||||
.. versionadded:: 1.20
|
||||
|
||||
Large parts of the NumPy API have :pep:`484`-style type annotations. In
|
||||
addition a number of type aliases are available to users, most prominently
|
||||
the two below:
|
||||
|
||||
- `ArrayLike`: objects that can be converted to arrays
|
||||
- `DTypeLike`: objects that can be converted to dtypes
|
||||
|
||||
.. _typing-extensions: https://pypi.org/project/typing-extensions/
|
||||
|
||||
Mypy plugin
|
||||
-----------
|
||||
|
||||
.. versionadded:: 1.21
|
||||
|
||||
.. automodule:: numpy.typing.mypy_plugin
|
||||
|
||||
.. currentmodule:: numpy.typing
|
||||
|
||||
Differences from the runtime NumPy API
|
||||
--------------------------------------
|
||||
|
||||
NumPy is very flexible. Trying to describe the full range of
|
||||
possibilities statically would result in types that are not very
|
||||
helpful. For that reason, the typed NumPy API is often stricter than
|
||||
the runtime NumPy API. This section describes some notable
|
||||
differences.
|
||||
|
||||
ArrayLike
|
||||
~~~~~~~~~
|
||||
|
||||
The `ArrayLike` type tries to avoid creating object arrays. For
|
||||
example,
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> np.array(x**2 for x in range(10))
|
||||
array(<generator object <genexpr> at ...>, dtype=object)
|
||||
|
||||
is valid NumPy code which will create a 0-dimensional object
|
||||
array. Type checkers will complain about the above example when using
|
||||
the NumPy types however. If you really intended to do the above, then
|
||||
you can either use a ``# type: ignore`` comment:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> np.array(x**2 for x in range(10)) # type: ignore
|
||||
|
||||
or explicitly type the array like object as `~typing.Any`:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> from typing import Any
|
||||
>>> array_like: Any = (x**2 for x in range(10))
|
||||
>>> np.array(array_like)
|
||||
array(<generator object <genexpr> at ...>, dtype=object)
|
||||
|
||||
ndarray
|
||||
~~~~~~~
|
||||
|
||||
It's possible to mutate the dtype of an array at runtime. For example,
|
||||
the following code is valid:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> x = np.array([1, 2])
|
||||
>>> x.dtype = np.bool
|
||||
|
||||
This sort of mutation is not allowed by the types. Users who want to
|
||||
write statically typed code should instead use the `numpy.ndarray.view`
|
||||
method to create a view of the array with a different dtype.
|
||||
|
||||
DTypeLike
|
||||
~~~~~~~~~
|
||||
|
||||
The `DTypeLike` type tries to avoid creation of dtype objects using
|
||||
dictionary of fields like below:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> x = np.dtype({"field1": (float, 1), "field2": (int, 3)})
|
||||
|
||||
Although this is valid NumPy code, the type checker will complain about it,
|
||||
since its usage is discouraged.
|
||||
Please see : :ref:`Data type objects <arrays.dtypes>`
|
||||
|
||||
Number precision
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
The precision of `numpy.number` subclasses is treated as a invariant generic
|
||||
parameter (see :class:`~NBitBase`), simplifying the annotating of processes
|
||||
involving precision-based casting.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> from typing import TypeVar
|
||||
>>> import numpy as np
|
||||
>>> import numpy.typing as npt
|
||||
|
||||
>>> T = TypeVar("T", bound=npt.NBitBase)
|
||||
>>> def func(a: "np.floating[T]", b: "np.floating[T]") -> "np.floating[T]":
|
||||
... ...
|
||||
|
||||
Consequently, the likes of `~numpy.float16`, `~numpy.float32` and
|
||||
`~numpy.float64` are still sub-types of `~numpy.floating`, but, contrary to
|
||||
runtime, they're not necessarily considered as sub-classes.
|
||||
|
||||
Timedelta64
|
||||
~~~~~~~~~~~
|
||||
|
||||
The `~numpy.timedelta64` class is not considered a subclass of
|
||||
`~numpy.signedinteger`, the former only inheriting from `~numpy.generic`
|
||||
while static type checking.
|
||||
|
||||
0D arrays
|
||||
~~~~~~~~~
|
||||
|
||||
During runtime numpy aggressively casts any passed 0D arrays into their
|
||||
corresponding `~numpy.generic` instance. Until the introduction of shape
|
||||
typing (see :pep:`646`) it is unfortunately not possible to make the
|
||||
necessary distinction between 0D and >0D arrays. While thus not strictly
|
||||
correct, all operations are that can potentially perform a 0D-array -> scalar
|
||||
cast are currently annotated as exclusively returning an `~numpy.ndarray`.
|
||||
|
||||
If it is known in advance that an operation *will* perform a
|
||||
0D-array -> scalar cast, then one can consider manually remedying the
|
||||
situation with either `typing.cast` or a ``# type: ignore`` comment.
|
||||
|
||||
Record array dtypes
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The dtype of `numpy.recarray`, and the :ref:`routines.array-creation.rec`
|
||||
functions in general, can be specified in one of two ways:
|
||||
|
||||
* Directly via the ``dtype`` argument.
|
||||
* With up to five helper arguments that operate via `numpy.rec.format_parser`:
|
||||
``formats``, ``names``, ``titles``, ``aligned`` and ``byteorder``.
|
||||
|
||||
These two approaches are currently typed as being mutually exclusive,
|
||||
*i.e.* if ``dtype`` is specified than one may not specify ``formats``.
|
||||
While this mutual exclusivity is not (strictly) enforced during runtime,
|
||||
combining both dtype specifiers can lead to unexpected or even downright
|
||||
buggy behavior.
|
||||
|
||||
API
|
||||
---
|
||||
|
||||
"""
|
||||
# NOTE: The API section will be appended with additional entries
|
||||
# further down in this file
|
||||
|
||||
from numpy._typing import (
|
||||
ArrayLike,
|
||||
DTypeLike,
|
||||
NBitBase,
|
||||
NDArray,
|
||||
)
|
||||
|
||||
__all__ = ["ArrayLike", "DTypeLike", "NBitBase", "NDArray"]
|
||||
|
||||
if __doc__ is not None:
|
||||
from numpy._typing._add_docstring import _docstrings
|
||||
__doc__ += _docstrings
|
||||
__doc__ += '\n.. autoclass:: numpy.typing.NBitBase\n'
|
||||
del _docstrings
|
||||
|
||||
from numpy._pytesttester import PytestTester
|
||||
test = PytestTester(__name__)
|
||||
del PytestTester
|
Binary file not shown.
Binary file not shown.
197
venv/lib/python3.12/site-packages/numpy/typing/mypy_plugin.py
Normal file
197
venv/lib/python3.12/site-packages/numpy/typing/mypy_plugin.py
Normal file
@ -0,0 +1,197 @@
|
||||
"""A mypy_ plugin for managing a number of platform-specific annotations.
|
||||
Its functionality can be split into three distinct parts:
|
||||
|
||||
* Assigning the (platform-dependent) precisions of certain `~numpy.number`
|
||||
subclasses, including the likes of `~numpy.int_`, `~numpy.intp` and
|
||||
`~numpy.longlong`. See the documentation on
|
||||
:ref:`scalar types <arrays.scalars.built-in>` for a comprehensive overview
|
||||
of the affected classes. Without the plugin the precision of all relevant
|
||||
classes will be inferred as `~typing.Any`.
|
||||
* Removing all extended-precision `~numpy.number` subclasses that are
|
||||
unavailable for the platform in question. Most notably this includes the
|
||||
likes of `~numpy.float128` and `~numpy.complex256`. Without the plugin *all*
|
||||
extended-precision types will, as far as mypy is concerned, be available
|
||||
to all platforms.
|
||||
* Assigning the (platform-dependent) precision of `~numpy.ctypeslib.c_intp`.
|
||||
Without the plugin the type will default to `ctypes.c_int64`.
|
||||
|
||||
.. versionadded:: 1.22
|
||||
|
||||
Examples
|
||||
--------
|
||||
To enable the plugin, one must add it to their mypy `configuration file`_:
|
||||
|
||||
.. code-block:: ini
|
||||
|
||||
[mypy]
|
||||
plugins = numpy.typing.mypy_plugin
|
||||
|
||||
.. _mypy: https://mypy-lang.org/
|
||||
.. _configuration file: https://mypy.readthedocs.io/en/stable/config_file.html
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable
|
||||
from typing import Final, TYPE_CHECKING, Callable
|
||||
|
||||
import numpy as np
|
||||
|
||||
try:
|
||||
import mypy.types
|
||||
from mypy.types import Type
|
||||
from mypy.plugin import Plugin, AnalyzeTypeContext
|
||||
from mypy.nodes import MypyFile, ImportFrom, Statement
|
||||
from mypy.build import PRI_MED
|
||||
|
||||
_HookFunc = Callable[[AnalyzeTypeContext], Type]
|
||||
MYPY_EX: None | ModuleNotFoundError = None
|
||||
except ModuleNotFoundError as ex:
|
||||
MYPY_EX = ex
|
||||
|
||||
__all__: list[str] = []
|
||||
|
||||
|
||||
def _get_precision_dict() -> dict[str, str]:
|
||||
names = [
|
||||
("_NBitByte", np.byte),
|
||||
("_NBitShort", np.short),
|
||||
("_NBitIntC", np.intc),
|
||||
("_NBitIntP", np.intp),
|
||||
("_NBitInt", np.int_),
|
||||
("_NBitLong", np.long),
|
||||
("_NBitLongLong", np.longlong),
|
||||
|
||||
("_NBitHalf", np.half),
|
||||
("_NBitSingle", np.single),
|
||||
("_NBitDouble", np.double),
|
||||
("_NBitLongDouble", np.longdouble),
|
||||
]
|
||||
ret = {}
|
||||
for name, typ in names:
|
||||
n: int = 8 * typ().dtype.itemsize
|
||||
ret[f'numpy._typing._nbit.{name}'] = f"numpy._{n}Bit"
|
||||
return ret
|
||||
|
||||
|
||||
def _get_extended_precision_list() -> list[str]:
|
||||
extended_names = [
|
||||
"uint128",
|
||||
"uint256",
|
||||
"int128",
|
||||
"int256",
|
||||
"float80",
|
||||
"float96",
|
||||
"float128",
|
||||
"float256",
|
||||
"complex160",
|
||||
"complex192",
|
||||
"complex256",
|
||||
"complex512",
|
||||
]
|
||||
return [i for i in extended_names if hasattr(np, i)]
|
||||
|
||||
|
||||
def _get_c_intp_name() -> str:
|
||||
# Adapted from `np.core._internal._getintp_ctype`
|
||||
char = np.dtype('n').char
|
||||
if char == 'i':
|
||||
return "c_int"
|
||||
elif char == 'l':
|
||||
return "c_long"
|
||||
elif char == 'q':
|
||||
return "c_longlong"
|
||||
else:
|
||||
return "c_long"
|
||||
|
||||
|
||||
#: A dictionary mapping type-aliases in `numpy._typing._nbit` to
|
||||
#: concrete `numpy.typing.NBitBase` subclasses.
|
||||
_PRECISION_DICT: Final = _get_precision_dict()
|
||||
|
||||
#: A list with the names of all extended precision `np.number` subclasses.
|
||||
_EXTENDED_PRECISION_LIST: Final = _get_extended_precision_list()
|
||||
|
||||
#: The name of the ctypes quivalent of `np.intp`
|
||||
_C_INTP: Final = _get_c_intp_name()
|
||||
|
||||
|
||||
def _hook(ctx: AnalyzeTypeContext) -> Type:
|
||||
"""Replace a type-alias with a concrete ``NBitBase`` subclass."""
|
||||
typ, _, api = ctx
|
||||
name = typ.name.split(".")[-1]
|
||||
name_new = _PRECISION_DICT[f"numpy._typing._nbit.{name}"]
|
||||
return api.named_type(name_new)
|
||||
|
||||
|
||||
if TYPE_CHECKING or MYPY_EX is None:
|
||||
def _index(iterable: Iterable[Statement], id: str) -> int:
|
||||
"""Identify the first ``ImportFrom`` instance the specified `id`."""
|
||||
for i, value in enumerate(iterable):
|
||||
if getattr(value, "id", None) == id:
|
||||
return i
|
||||
raise ValueError("Failed to identify a `ImportFrom` instance "
|
||||
f"with the following id: {id!r}")
|
||||
|
||||
def _override_imports(
|
||||
file: MypyFile,
|
||||
module: str,
|
||||
imports: list[tuple[str, None | str]],
|
||||
) -> None:
|
||||
"""Override the first `module`-based import with new `imports`."""
|
||||
# Construct a new `from module import y` statement
|
||||
import_obj = ImportFrom(module, 0, names=imports)
|
||||
import_obj.is_top_level = True
|
||||
|
||||
# Replace the first `module`-based import statement with `import_obj`
|
||||
for lst in [file.defs, file.imports]: # type: list[Statement]
|
||||
i = _index(lst, module)
|
||||
lst[i] = import_obj
|
||||
|
||||
class _NumpyPlugin(Plugin):
|
||||
"""A mypy plugin for handling versus numpy-specific typing tasks."""
|
||||
|
||||
def get_type_analyze_hook(self, fullname: str) -> None | _HookFunc:
|
||||
"""Set the precision of platform-specific `numpy.number`
|
||||
subclasses.
|
||||
|
||||
For example: `numpy.int_`, `numpy.longlong` and `numpy.longdouble`.
|
||||
"""
|
||||
if fullname in _PRECISION_DICT:
|
||||
return _hook
|
||||
return None
|
||||
|
||||
def get_additional_deps(
|
||||
self, file: MypyFile
|
||||
) -> list[tuple[int, str, int]]:
|
||||
"""Handle all import-based overrides.
|
||||
|
||||
* Import platform-specific extended-precision `numpy.number`
|
||||
subclasses (*e.g.* `numpy.float96`, `numpy.float128` and
|
||||
`numpy.complex256`).
|
||||
* Import the appropriate `ctypes` equivalent to `numpy.intp`.
|
||||
|
||||
"""
|
||||
ret = [(PRI_MED, file.fullname, -1)]
|
||||
|
||||
if file.fullname == "numpy":
|
||||
_override_imports(
|
||||
file, "numpy._typing._extended_precision",
|
||||
imports=[(v, v) for v in _EXTENDED_PRECISION_LIST],
|
||||
)
|
||||
elif file.fullname == "numpy.ctypeslib":
|
||||
_override_imports(
|
||||
file, "ctypes",
|
||||
imports=[(_C_INTP, "_c_intp")],
|
||||
)
|
||||
return ret
|
||||
|
||||
def plugin(version: str) -> type[_NumpyPlugin]:
|
||||
"""An entry-point for mypy."""
|
||||
return _NumpyPlugin
|
||||
|
||||
else:
|
||||
def plugin(version: str) -> type[_NumpyPlugin]:
|
||||
"""An entry-point for mypy."""
|
||||
raise MYPY_EX
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,123 @@
|
||||
from typing import Any
|
||||
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
b_ = np.bool()
|
||||
dt = np.datetime64(0, "D")
|
||||
td = np.timedelta64(0, "D")
|
||||
|
||||
AR_b: npt.NDArray[np.bool]
|
||||
AR_u: npt.NDArray[np.uint32]
|
||||
AR_i: npt.NDArray[np.int64]
|
||||
AR_f: npt.NDArray[np.float64]
|
||||
AR_c: npt.NDArray[np.complex128]
|
||||
AR_m: npt.NDArray[np.timedelta64]
|
||||
AR_M: npt.NDArray[np.datetime64]
|
||||
|
||||
ANY: Any
|
||||
|
||||
AR_LIKE_b: list[bool]
|
||||
AR_LIKE_u: list[np.uint32]
|
||||
AR_LIKE_i: list[int]
|
||||
AR_LIKE_f: list[float]
|
||||
AR_LIKE_c: list[complex]
|
||||
AR_LIKE_m: list[np.timedelta64]
|
||||
AR_LIKE_M: list[np.datetime64]
|
||||
|
||||
# Array subtraction
|
||||
|
||||
# NOTE: mypys `NoReturn` errors are, unfortunately, not that great
|
||||
_1 = AR_b - AR_LIKE_b # E: Need type annotation
|
||||
_2 = AR_LIKE_b - AR_b # E: Need type annotation
|
||||
AR_i - bytes() # E: No overload variant
|
||||
|
||||
AR_f - AR_LIKE_m # E: Unsupported operand types
|
||||
AR_f - AR_LIKE_M # E: Unsupported operand types
|
||||
AR_c - AR_LIKE_m # E: Unsupported operand types
|
||||
AR_c - AR_LIKE_M # E: Unsupported operand types
|
||||
|
||||
AR_m - AR_LIKE_f # E: Unsupported operand types
|
||||
AR_M - AR_LIKE_f # E: Unsupported operand types
|
||||
AR_m - AR_LIKE_c # E: Unsupported operand types
|
||||
AR_M - AR_LIKE_c # E: Unsupported operand types
|
||||
|
||||
AR_m - AR_LIKE_M # E: Unsupported operand types
|
||||
AR_LIKE_m - AR_M # E: Unsupported operand types
|
||||
|
||||
# array floor division
|
||||
|
||||
AR_M // AR_LIKE_b # E: Unsupported operand types
|
||||
AR_M // AR_LIKE_u # E: Unsupported operand types
|
||||
AR_M // AR_LIKE_i # E: Unsupported operand types
|
||||
AR_M // AR_LIKE_f # E: Unsupported operand types
|
||||
AR_M // AR_LIKE_c # E: Unsupported operand types
|
||||
AR_M // AR_LIKE_m # E: Unsupported operand types
|
||||
AR_M // AR_LIKE_M # E: Unsupported operand types
|
||||
|
||||
AR_b // AR_LIKE_M # E: Unsupported operand types
|
||||
AR_u // AR_LIKE_M # E: Unsupported operand types
|
||||
AR_i // AR_LIKE_M # E: Unsupported operand types
|
||||
AR_f // AR_LIKE_M # E: Unsupported operand types
|
||||
AR_c // AR_LIKE_M # E: Unsupported operand types
|
||||
AR_m // AR_LIKE_M # E: Unsupported operand types
|
||||
AR_M // AR_LIKE_M # E: Unsupported operand types
|
||||
|
||||
_3 = AR_m // AR_LIKE_b # E: Need type annotation
|
||||
AR_m // AR_LIKE_c # E: Unsupported operand types
|
||||
|
||||
AR_b // AR_LIKE_m # E: Unsupported operand types
|
||||
AR_u // AR_LIKE_m # E: Unsupported operand types
|
||||
AR_i // AR_LIKE_m # E: Unsupported operand types
|
||||
AR_f // AR_LIKE_m # E: Unsupported operand types
|
||||
AR_c // AR_LIKE_m # E: Unsupported operand types
|
||||
|
||||
# Array multiplication
|
||||
|
||||
AR_b *= AR_LIKE_u # E: incompatible type
|
||||
AR_b *= AR_LIKE_i # E: incompatible type
|
||||
AR_b *= AR_LIKE_f # E: incompatible type
|
||||
AR_b *= AR_LIKE_c # E: incompatible type
|
||||
AR_b *= AR_LIKE_m # E: incompatible type
|
||||
|
||||
AR_u *= AR_LIKE_i # E: incompatible type
|
||||
AR_u *= AR_LIKE_f # E: incompatible type
|
||||
AR_u *= AR_LIKE_c # E: incompatible type
|
||||
AR_u *= AR_LIKE_m # E: incompatible type
|
||||
|
||||
AR_i *= AR_LIKE_f # E: incompatible type
|
||||
AR_i *= AR_LIKE_c # E: incompatible type
|
||||
AR_i *= AR_LIKE_m # E: incompatible type
|
||||
|
||||
AR_f *= AR_LIKE_c # E: incompatible type
|
||||
AR_f *= AR_LIKE_m # E: incompatible type
|
||||
|
||||
# Array power
|
||||
|
||||
AR_b **= AR_LIKE_b # E: Invalid self argument
|
||||
AR_b **= AR_LIKE_u # E: Invalid self argument
|
||||
AR_b **= AR_LIKE_i # E: Invalid self argument
|
||||
AR_b **= AR_LIKE_f # E: Invalid self argument
|
||||
AR_b **= AR_LIKE_c # E: Invalid self argument
|
||||
|
||||
AR_u **= AR_LIKE_i # E: incompatible type
|
||||
AR_u **= AR_LIKE_f # E: incompatible type
|
||||
AR_u **= AR_LIKE_c # E: incompatible type
|
||||
|
||||
AR_i **= AR_LIKE_f # E: incompatible type
|
||||
AR_i **= AR_LIKE_c # E: incompatible type
|
||||
|
||||
AR_f **= AR_LIKE_c # E: incompatible type
|
||||
|
||||
# Scalars
|
||||
|
||||
b_ - b_ # E: No overload variant
|
||||
|
||||
dt + dt # E: Unsupported operand types
|
||||
td - dt # E: Unsupported operand types
|
||||
td % 1 # E: Unsupported operand types
|
||||
td / dt # E: No overload
|
||||
td % dt # E: Unsupported operand types
|
||||
|
||||
-b_ # E: Unsupported operand type
|
||||
+b_ # E: Unsupported operand type
|
@ -0,0 +1,34 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
a: npt.NDArray[np.float64]
|
||||
generator = (i for i in range(10))
|
||||
|
||||
np.require(a, requirements=1) # E: No overload variant
|
||||
np.require(a, requirements="TEST") # E: incompatible type
|
||||
|
||||
np.zeros("test") # E: incompatible type
|
||||
np.zeros() # E: require at least one argument
|
||||
|
||||
np.ones("test") # E: incompatible type
|
||||
np.ones() # E: require at least one argument
|
||||
|
||||
np.array(0, float, True) # E: No overload variant
|
||||
|
||||
np.linspace(None, 'bob') # E: No overload variant
|
||||
np.linspace(0, 2, num=10.0) # E: No overload variant
|
||||
np.linspace(0, 2, endpoint='True') # E: No overload variant
|
||||
np.linspace(0, 2, retstep=b'False') # E: No overload variant
|
||||
np.linspace(0, 2, dtype=0) # E: No overload variant
|
||||
np.linspace(0, 2, axis=None) # E: No overload variant
|
||||
|
||||
np.logspace(None, 'bob') # E: No overload variant
|
||||
np.logspace(0, 2, base=None) # E: No overload variant
|
||||
|
||||
np.geomspace(None, 'bob') # E: No overload variant
|
||||
|
||||
np.stack(generator) # E: No overload variant
|
||||
np.hstack({1, 2}) # E: No overload variant
|
||||
np.vstack(1) # E: No overload variant
|
||||
|
||||
np.array([1], like=1) # E: No overload variant
|
@ -0,0 +1,16 @@
|
||||
import numpy as np
|
||||
from numpy._typing import ArrayLike
|
||||
|
||||
|
||||
class A:
|
||||
pass
|
||||
|
||||
|
||||
x1: ArrayLike = (i for i in range(10)) # E: Incompatible types in assignment
|
||||
x2: ArrayLike = A() # E: Incompatible types in assignment
|
||||
x3: ArrayLike = {1: "foo", 2: "bar"} # E: Incompatible types in assignment
|
||||
|
||||
scalar = np.int64(1)
|
||||
scalar.__array__(dtype=np.float64) # E: No overload variant
|
||||
array = np.array([1])
|
||||
array.__array__(dtype=np.float64) # E: No overload variant
|
@ -0,0 +1,6 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_i8: npt.NDArray[np.int64]
|
||||
|
||||
np.pad(AR_i8, 2, mode="bob") # E: No overload variant
|
@ -0,0 +1,16 @@
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR: npt.NDArray[np.float64]
|
||||
func1: Callable[[Any], str]
|
||||
func2: Callable[[np.integer[Any]], str]
|
||||
|
||||
np.array2string(AR, style=None) # E: Unexpected keyword argument
|
||||
np.array2string(AR, legacy="1.14") # E: incompatible type
|
||||
np.array2string(AR, sign="*") # E: incompatible type
|
||||
np.array2string(AR, floatmode="default") # E: incompatible type
|
||||
np.array2string(AR, formatter={"A": func1}) # E: incompatible type
|
||||
np.array2string(AR, formatter={"float": func2}) # E: Incompatible types
|
@ -0,0 +1,14 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_i8: npt.NDArray[np.int64]
|
||||
ar_iter = np.lib.Arrayterator(AR_i8)
|
||||
|
||||
np.lib.Arrayterator(np.int64()) # E: incompatible type
|
||||
ar_iter.shape = (10, 5) # E: is read-only
|
||||
ar_iter[None] # E: Invalid index type
|
||||
ar_iter[None, 1] # E: Invalid index type
|
||||
ar_iter[np.intp()] # E: Invalid index type
|
||||
ar_iter[np.intp(), ...] # E: Invalid index type
|
||||
ar_iter[AR_i8] # E: Invalid index type
|
||||
ar_iter[AR_i8, :] # E: Invalid index type
|
@ -0,0 +1,21 @@
|
||||
import numpy as np
|
||||
|
||||
i8 = np.int64()
|
||||
i4 = np.int32()
|
||||
u8 = np.uint64()
|
||||
b_ = np.bool()
|
||||
i = int()
|
||||
|
||||
f8 = np.float64()
|
||||
|
||||
b_ >> f8 # E: No overload variant
|
||||
i8 << f8 # E: No overload variant
|
||||
i | f8 # E: Unsupported operand types
|
||||
i8 ^ f8 # E: No overload variant
|
||||
u8 & f8 # E: No overload variant
|
||||
~f8 # E: Unsupported operand type
|
||||
# TODO: Certain mixes like i4 << u8 go to float and thus should fail
|
||||
|
||||
# mypys' error message for `NoReturn` is unfortunately pretty bad
|
||||
# TODO: Re-enable this once we add support for numerical precision for `number`s
|
||||
# a = u8 | 0 # E: Need type annotation
|
@ -0,0 +1,69 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_U: npt.NDArray[np.str_]
|
||||
AR_S: npt.NDArray[np.bytes_]
|
||||
|
||||
np.char.equal(AR_U, AR_S) # E: incompatible type
|
||||
|
||||
np.char.not_equal(AR_U, AR_S) # E: incompatible type
|
||||
|
||||
np.char.greater_equal(AR_U, AR_S) # E: incompatible type
|
||||
|
||||
np.char.less_equal(AR_U, AR_S) # E: incompatible type
|
||||
|
||||
np.char.greater(AR_U, AR_S) # E: incompatible type
|
||||
|
||||
np.char.less(AR_U, AR_S) # E: incompatible type
|
||||
|
||||
np.char.encode(AR_S) # E: incompatible type
|
||||
np.char.decode(AR_U) # E: incompatible type
|
||||
|
||||
np.char.join(AR_U, b"_") # E: incompatible type
|
||||
np.char.join(AR_S, "_") # E: incompatible type
|
||||
|
||||
np.char.ljust(AR_U, 5, fillchar=b"a") # E: incompatible type
|
||||
np.char.ljust(AR_S, 5, fillchar="a") # E: incompatible type
|
||||
np.char.rjust(AR_U, 5, fillchar=b"a") # E: incompatible type
|
||||
np.char.rjust(AR_S, 5, fillchar="a") # E: incompatible type
|
||||
|
||||
np.char.lstrip(AR_U, chars=b"a") # E: incompatible type
|
||||
np.char.lstrip(AR_S, chars="a") # E: incompatible type
|
||||
np.char.strip(AR_U, chars=b"a") # E: incompatible type
|
||||
np.char.strip(AR_S, chars="a") # E: incompatible type
|
||||
np.char.rstrip(AR_U, chars=b"a") # E: incompatible type
|
||||
np.char.rstrip(AR_S, chars="a") # E: incompatible type
|
||||
|
||||
np.char.partition(AR_U, b"a") # E: incompatible type
|
||||
np.char.partition(AR_S, "a") # E: incompatible type
|
||||
np.char.rpartition(AR_U, b"a") # E: incompatible type
|
||||
np.char.rpartition(AR_S, "a") # E: incompatible type
|
||||
|
||||
np.char.replace(AR_U, b"_", b"-") # E: incompatible type
|
||||
np.char.replace(AR_S, "_", "-") # E: incompatible type
|
||||
|
||||
np.char.split(AR_U, b"_") # E: incompatible type
|
||||
np.char.split(AR_S, "_") # E: incompatible type
|
||||
np.char.rsplit(AR_U, b"_") # E: incompatible type
|
||||
np.char.rsplit(AR_S, "_") # E: incompatible type
|
||||
|
||||
np.char.count(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
np.char.count(AR_S, "a", end=9) # E: incompatible type
|
||||
|
||||
np.char.endswith(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
np.char.endswith(AR_S, "a", end=9) # E: incompatible type
|
||||
np.char.startswith(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
np.char.startswith(AR_S, "a", end=9) # E: incompatible type
|
||||
|
||||
np.char.find(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
np.char.find(AR_S, "a", end=9) # E: incompatible type
|
||||
np.char.rfind(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
np.char.rfind(AR_S, "a", end=9) # E: incompatible type
|
||||
|
||||
np.char.index(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
np.char.index(AR_S, "a", end=9) # E: incompatible type
|
||||
np.char.rindex(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
np.char.rindex(AR_S, "a", end=9) # E: incompatible type
|
||||
|
||||
np.char.isdecimal(AR_S) # E: incompatible type
|
||||
np.char.isnumeric(AR_S) # E: incompatible type
|
@ -0,0 +1,62 @@
|
||||
import numpy as np
|
||||
from typing import Any
|
||||
|
||||
AR_U: np.char.chararray[Any, np.dtype[np.str_]]
|
||||
AR_S: np.char.chararray[Any, np.dtype[np.bytes_]]
|
||||
|
||||
AR_S.encode() # E: Invalid self argument
|
||||
AR_U.decode() # E: Invalid self argument
|
||||
|
||||
AR_U.join(b"_") # E: incompatible type
|
||||
AR_S.join("_") # E: incompatible type
|
||||
|
||||
AR_U.ljust(5, fillchar=b"a") # E: incompatible type
|
||||
AR_S.ljust(5, fillchar="a") # E: incompatible type
|
||||
AR_U.rjust(5, fillchar=b"a") # E: incompatible type
|
||||
AR_S.rjust(5, fillchar="a") # E: incompatible type
|
||||
|
||||
AR_U.lstrip(chars=b"a") # E: incompatible type
|
||||
AR_S.lstrip(chars="a") # E: incompatible type
|
||||
AR_U.strip(chars=b"a") # E: incompatible type
|
||||
AR_S.strip(chars="a") # E: incompatible type
|
||||
AR_U.rstrip(chars=b"a") # E: incompatible type
|
||||
AR_S.rstrip(chars="a") # E: incompatible type
|
||||
|
||||
AR_U.partition(b"a") # E: incompatible type
|
||||
AR_S.partition("a") # E: incompatible type
|
||||
AR_U.rpartition(b"a") # E: incompatible type
|
||||
AR_S.rpartition("a") # E: incompatible type
|
||||
|
||||
AR_U.replace(b"_", b"-") # E: incompatible type
|
||||
AR_S.replace("_", "-") # E: incompatible type
|
||||
|
||||
AR_U.split(b"_") # E: incompatible type
|
||||
AR_S.split("_") # E: incompatible type
|
||||
AR_S.split(1) # E: incompatible type
|
||||
AR_U.rsplit(b"_") # E: incompatible type
|
||||
AR_S.rsplit("_") # E: incompatible type
|
||||
|
||||
AR_U.count(b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
AR_S.count("a", end=9) # E: incompatible type
|
||||
|
||||
AR_U.endswith(b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
AR_S.endswith("a", end=9) # E: incompatible type
|
||||
AR_U.startswith(b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
AR_S.startswith("a", end=9) # E: incompatible type
|
||||
|
||||
AR_U.find(b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
AR_S.find("a", end=9) # E: incompatible type
|
||||
AR_U.rfind(b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
AR_S.rfind("a", end=9) # E: incompatible type
|
||||
|
||||
AR_U.index(b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
AR_S.index("a", end=9) # E: incompatible type
|
||||
AR_U.rindex(b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
AR_S.rindex("a", end=9) # E: incompatible type
|
||||
|
||||
AR_U == AR_S # E: Unsupported operand types
|
||||
AR_U != AR_S # E: Unsupported operand types
|
||||
AR_U >= AR_S # E: Unsupported operand types
|
||||
AR_U <= AR_S # E: Unsupported operand types
|
||||
AR_U > AR_S # E: Unsupported operand types
|
||||
AR_U < AR_S # E: Unsupported operand types
|
@ -0,0 +1,27 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_i: npt.NDArray[np.int64]
|
||||
AR_f: npt.NDArray[np.float64]
|
||||
AR_c: npt.NDArray[np.complex128]
|
||||
AR_m: npt.NDArray[np.timedelta64]
|
||||
AR_M: npt.NDArray[np.datetime64]
|
||||
|
||||
AR_f > AR_m # E: Unsupported operand types
|
||||
AR_c > AR_m # E: Unsupported operand types
|
||||
|
||||
AR_m > AR_f # E: Unsupported operand types
|
||||
AR_m > AR_c # E: Unsupported operand types
|
||||
|
||||
AR_i > AR_M # E: Unsupported operand types
|
||||
AR_f > AR_M # E: Unsupported operand types
|
||||
AR_m > AR_M # E: Unsupported operand types
|
||||
|
||||
AR_M > AR_i # E: Unsupported operand types
|
||||
AR_M > AR_f # E: Unsupported operand types
|
||||
AR_M > AR_m # E: Unsupported operand types
|
||||
|
||||
AR_i > str() # E: No overload variant
|
||||
AR_i > bytes() # E: No overload variant
|
||||
str() > AR_M # E: Unsupported operand types
|
||||
bytes() > AR_M # E: Unsupported operand types
|
@ -0,0 +1,3 @@
|
||||
import numpy as np
|
||||
|
||||
np.little_endian = np.little_endian # E: Cannot assign to final
|
@ -0,0 +1,15 @@
|
||||
from pathlib import Path
|
||||
import numpy as np
|
||||
|
||||
path: Path
|
||||
d1: np.lib.npyio.DataSource
|
||||
|
||||
d1.abspath(path) # E: incompatible type
|
||||
d1.abspath(b"...") # E: incompatible type
|
||||
|
||||
d1.exists(path) # E: incompatible type
|
||||
d1.exists(b"...") # E: incompatible type
|
||||
|
||||
d1.open(path, "r") # E: incompatible type
|
||||
d1.open(b"...", encoding="utf8") # E: incompatible type
|
||||
d1.open(None, newline="/n") # E: incompatible type
|
@ -0,0 +1,20 @@
|
||||
import numpy as np
|
||||
|
||||
|
||||
class Test1:
|
||||
not_dtype = np.dtype(float)
|
||||
|
||||
|
||||
class Test2:
|
||||
dtype = float
|
||||
|
||||
|
||||
np.dtype(Test1()) # E: No overload variant of "dtype" matches
|
||||
np.dtype(Test2()) # E: incompatible type
|
||||
|
||||
np.dtype( # E: No overload variant of "dtype" matches
|
||||
{
|
||||
"field1": (float, 1),
|
||||
"field2": (int, 3),
|
||||
}
|
||||
)
|
@ -0,0 +1,12 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_i: npt.NDArray[np.int64]
|
||||
AR_f: npt.NDArray[np.float64]
|
||||
AR_m: npt.NDArray[np.timedelta64]
|
||||
AR_U: npt.NDArray[np.str_]
|
||||
|
||||
np.einsum("i,i->i", AR_i, AR_m) # E: incompatible type
|
||||
np.einsum("i,i->i", AR_f, AR_f, dtype=np.int32) # E: incompatible type
|
||||
np.einsum("i,i->i", AR_i, AR_i, out=AR_U) # E: Value of type variable "_ArrayType" of "einsum" cannot be
|
||||
np.einsum("i,i->i", AR_i, AR_i, out=AR_U, casting="unsafe") # E: No overload variant
|
@ -0,0 +1,11 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_f8: npt.NDArray[np.float64]
|
||||
|
||||
# NOTE: Mypy bug presumably due to the special-casing of heterogeneous tuples;
|
||||
# xref numpy/numpy#20901
|
||||
#
|
||||
# The expected output should be no different than, e.g., when using a
|
||||
# list instead of a tuple
|
||||
np.concatenate(([1], AR_f8)) # E: Argument 1 to "concatenate" has incompatible type
|
@ -0,0 +1,25 @@
|
||||
from typing import Any
|
||||
|
||||
import numpy as np
|
||||
import numpy._typing as npt
|
||||
|
||||
|
||||
class Index:
|
||||
def __index__(self) -> int:
|
||||
...
|
||||
|
||||
|
||||
a: np.flatiter[npt.NDArray[np.float64]]
|
||||
supports_array: npt._SupportsArray[np.dtype[np.float64]]
|
||||
|
||||
a.base = Any # E: Property "base" defined in "flatiter" is read-only
|
||||
a.coords = Any # E: Property "coords" defined in "flatiter" is read-only
|
||||
a.index = Any # E: Property "index" defined in "flatiter" is read-only
|
||||
a.copy(order='C') # E: Unexpected keyword argument
|
||||
|
||||
# NOTE: Contrary to `ndarray.__getitem__` its counterpart in `flatiter`
|
||||
# does not accept objects with the `__array__` or `__index__` protocols;
|
||||
# boolean indexing is just plain broken (gh-17175)
|
||||
a[np.bool()] # E: No overload variant of "__getitem__"
|
||||
a[Index()] # E: No overload variant of "__getitem__"
|
||||
a[supports_array] # E: No overload variant of "__getitem__"
|
@ -0,0 +1,161 @@
|
||||
"""Tests for :mod:`numpy._core.fromnumeric`."""
|
||||
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
A = np.array(True, ndmin=2, dtype=bool)
|
||||
A.setflags(write=False)
|
||||
AR_U: npt.NDArray[np.str_]
|
||||
|
||||
a = np.bool(True)
|
||||
|
||||
np.take(a, None) # E: No overload variant
|
||||
np.take(a, axis=1.0) # E: No overload variant
|
||||
np.take(A, out=1) # E: No overload variant
|
||||
np.take(A, mode="bob") # E: No overload variant
|
||||
|
||||
np.reshape(a, None) # E: No overload variant
|
||||
np.reshape(A, 1, order="bob") # E: No overload variant
|
||||
|
||||
np.choose(a, None) # E: No overload variant
|
||||
np.choose(a, out=1.0) # E: No overload variant
|
||||
np.choose(A, mode="bob") # E: No overload variant
|
||||
|
||||
np.repeat(a, None) # E: No overload variant
|
||||
np.repeat(A, 1, axis=1.0) # E: No overload variant
|
||||
|
||||
np.swapaxes(A, None, 1) # E: No overload variant
|
||||
np.swapaxes(A, 1, [0]) # E: No overload variant
|
||||
|
||||
np.transpose(A, axes=1.0) # E: No overload variant
|
||||
|
||||
np.partition(a, None) # E: No overload variant
|
||||
np.partition( # E: No overload variant
|
||||
a, 0, axis="bob"
|
||||
)
|
||||
np.partition( # E: No overload variant
|
||||
A, 0, kind="bob"
|
||||
)
|
||||
np.partition(
|
||||
A, 0, order=range(5) # E: Argument "order" to "partition" has incompatible type
|
||||
)
|
||||
|
||||
np.argpartition(
|
||||
a, None # E: incompatible type
|
||||
)
|
||||
np.argpartition(
|
||||
a, 0, axis="bob" # E: incompatible type
|
||||
)
|
||||
np.argpartition(
|
||||
A, 0, kind="bob" # E: incompatible type
|
||||
)
|
||||
np.argpartition(
|
||||
A, 0, order=range(5) # E: Argument "order" to "argpartition" has incompatible type
|
||||
)
|
||||
|
||||
np.sort(A, axis="bob") # E: No overload variant
|
||||
np.sort(A, kind="bob") # E: No overload variant
|
||||
np.sort(A, order=range(5)) # E: Argument "order" to "sort" has incompatible type
|
||||
|
||||
np.argsort(A, axis="bob") # E: Argument "axis" to "argsort" has incompatible type
|
||||
np.argsort(A, kind="bob") # E: Argument "kind" to "argsort" has incompatible type
|
||||
np.argsort(A, order=range(5)) # E: Argument "order" to "argsort" has incompatible type
|
||||
|
||||
np.argmax(A, axis="bob") # E: No overload variant of "argmax" matches argument type
|
||||
np.argmax(A, kind="bob") # E: No overload variant of "argmax" matches argument type
|
||||
|
||||
np.argmin(A, axis="bob") # E: No overload variant of "argmin" matches argument type
|
||||
np.argmin(A, kind="bob") # E: No overload variant of "argmin" matches argument type
|
||||
|
||||
np.searchsorted( # E: No overload variant of "searchsorted" matches argument type
|
||||
A[0], 0, side="bob"
|
||||
)
|
||||
np.searchsorted( # E: No overload variant of "searchsorted" matches argument type
|
||||
A[0], 0, sorter=1.0
|
||||
)
|
||||
|
||||
np.resize(A, 1.0) # E: No overload variant
|
||||
|
||||
np.squeeze(A, 1.0) # E: No overload variant of "squeeze" matches argument type
|
||||
|
||||
np.diagonal(A, offset=None) # E: No overload variant
|
||||
np.diagonal(A, axis1="bob") # E: No overload variant
|
||||
np.diagonal(A, axis2=[]) # E: No overload variant
|
||||
|
||||
np.trace(A, offset=None) # E: No overload variant
|
||||
np.trace(A, axis1="bob") # E: No overload variant
|
||||
np.trace(A, axis2=[]) # E: No overload variant
|
||||
|
||||
np.ravel(a, order="bob") # E: No overload variant
|
||||
|
||||
np.compress( # E: No overload variant
|
||||
[True], A, axis=1.0
|
||||
)
|
||||
|
||||
np.clip(a, 1, 2, out=1) # E: No overload variant of "clip" matches argument type
|
||||
|
||||
np.sum(a, axis=1.0) # E: No overload variant
|
||||
np.sum(a, keepdims=1.0) # E: No overload variant
|
||||
np.sum(a, initial=[1]) # E: No overload variant
|
||||
|
||||
np.all(a, axis=1.0) # E: No overload variant
|
||||
np.all(a, keepdims=1.0) # E: No overload variant
|
||||
np.all(a, out=1.0) # E: No overload variant
|
||||
|
||||
np.any(a, axis=1.0) # E: No overload variant
|
||||
np.any(a, keepdims=1.0) # E: No overload variant
|
||||
np.any(a, out=1.0) # E: No overload variant
|
||||
|
||||
np.cumsum(a, axis=1.0) # E: No overload variant
|
||||
np.cumsum(a, dtype=1.0) # E: No overload variant
|
||||
np.cumsum(a, out=1.0) # E: No overload variant
|
||||
|
||||
np.ptp(a, axis=1.0) # E: No overload variant
|
||||
np.ptp(a, keepdims=1.0) # E: No overload variant
|
||||
np.ptp(a, out=1.0) # E: No overload variant
|
||||
|
||||
np.amax(a, axis=1.0) # E: No overload variant
|
||||
np.amax(a, keepdims=1.0) # E: No overload variant
|
||||
np.amax(a, out=1.0) # E: No overload variant
|
||||
np.amax(a, initial=[1.0]) # E: No overload variant
|
||||
np.amax(a, where=[1.0]) # E: incompatible type
|
||||
|
||||
np.amin(a, axis=1.0) # E: No overload variant
|
||||
np.amin(a, keepdims=1.0) # E: No overload variant
|
||||
np.amin(a, out=1.0) # E: No overload variant
|
||||
np.amin(a, initial=[1.0]) # E: No overload variant
|
||||
np.amin(a, where=[1.0]) # E: incompatible type
|
||||
|
||||
np.prod(a, axis=1.0) # E: No overload variant
|
||||
np.prod(a, out=False) # E: No overload variant
|
||||
np.prod(a, keepdims=1.0) # E: No overload variant
|
||||
np.prod(a, initial=int) # E: No overload variant
|
||||
np.prod(a, where=1.0) # E: No overload variant
|
||||
np.prod(AR_U) # E: incompatible type
|
||||
|
||||
np.cumprod(a, axis=1.0) # E: No overload variant
|
||||
np.cumprod(a, out=False) # E: No overload variant
|
||||
np.cumprod(AR_U) # E: incompatible type
|
||||
|
||||
np.size(a, axis=1.0) # E: Argument "axis" to "size" has incompatible type
|
||||
|
||||
np.around(a, decimals=1.0) # E: No overload variant
|
||||
np.around(a, out=type) # E: No overload variant
|
||||
np.around(AR_U) # E: incompatible type
|
||||
|
||||
np.mean(a, axis=1.0) # E: No overload variant
|
||||
np.mean(a, out=False) # E: No overload variant
|
||||
np.mean(a, keepdims=1.0) # E: No overload variant
|
||||
np.mean(AR_U) # E: incompatible type
|
||||
|
||||
np.std(a, axis=1.0) # E: No overload variant
|
||||
np.std(a, out=False) # E: No overload variant
|
||||
np.std(a, ddof='test') # E: No overload variant
|
||||
np.std(a, keepdims=1.0) # E: No overload variant
|
||||
np.std(AR_U) # E: incompatible type
|
||||
|
||||
np.var(a, axis=1.0) # E: No overload variant
|
||||
np.var(a, out=False) # E: No overload variant
|
||||
np.var(a, ddof='test') # E: No overload variant
|
||||
np.var(a, keepdims=1.0) # E: No overload variant
|
||||
np.var(AR_U) # E: incompatible type
|
@ -0,0 +1,12 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_i8: npt.NDArray[np.int64]
|
||||
AR_f8: npt.NDArray[np.float64]
|
||||
|
||||
np.histogram_bin_edges(AR_i8, range=(0, 1, 2)) # E: incompatible type
|
||||
|
||||
np.histogram(AR_i8, range=(0, 1, 2)) # E: incompatible type
|
||||
|
||||
np.histogramdd(AR_i8, range=(0, 1)) # E: incompatible type
|
||||
np.histogramdd(AR_i8, range=[(0, 1, 2)]) # E: incompatible type
|
@ -0,0 +1,14 @@
|
||||
import numpy as np
|
||||
|
||||
AR_LIKE_i: list[int]
|
||||
AR_LIKE_f: list[float]
|
||||
|
||||
np.ndindex([1, 2, 3]) # E: No overload variant
|
||||
np.unravel_index(AR_LIKE_f, (1, 2, 3)) # E: incompatible type
|
||||
np.ravel_multi_index(AR_LIKE_i, (1, 2, 3), mode="bob") # E: No overload variant
|
||||
np.mgrid[1] # E: Invalid index type
|
||||
np.mgrid[...] # E: Invalid index type
|
||||
np.ogrid[1] # E: Invalid index type
|
||||
np.ogrid[...] # E: Invalid index type
|
||||
np.fill_diagonal(AR_LIKE_f, 2) # E: incompatible type
|
||||
np.diag_indices(1.0) # E: incompatible type
|
@ -0,0 +1,51 @@
|
||||
from typing import Any
|
||||
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_f8: npt.NDArray[np.float64]
|
||||
AR_c16: npt.NDArray[np.complex128]
|
||||
AR_m: npt.NDArray[np.timedelta64]
|
||||
AR_M: npt.NDArray[np.datetime64]
|
||||
AR_O: npt.NDArray[np.object_]
|
||||
|
||||
def func(a: int) -> None: ...
|
||||
|
||||
np.average(AR_m) # E: incompatible type
|
||||
np.select(1, [AR_f8]) # E: incompatible type
|
||||
np.angle(AR_m) # E: incompatible type
|
||||
np.unwrap(AR_m) # E: incompatible type
|
||||
np.unwrap(AR_c16) # E: incompatible type
|
||||
np.trim_zeros(1) # E: incompatible type
|
||||
np.place(1, [True], 1.5) # E: incompatible type
|
||||
np.vectorize(1) # E: incompatible type
|
||||
np.place(AR_f8, slice(None), 5) # E: incompatible type
|
||||
|
||||
np.interp(AR_f8, AR_c16, AR_f8) # E: incompatible type
|
||||
np.interp(AR_c16, AR_f8, AR_f8) # E: incompatible type
|
||||
np.interp(AR_f8, AR_f8, AR_f8, period=AR_c16) # E: No overload variant
|
||||
np.interp(AR_f8, AR_f8, AR_O) # E: incompatible type
|
||||
|
||||
np.cov(AR_m) # E: incompatible type
|
||||
np.cov(AR_O) # E: incompatible type
|
||||
np.corrcoef(AR_m) # E: incompatible type
|
||||
np.corrcoef(AR_O) # E: incompatible type
|
||||
np.corrcoef(AR_f8, bias=True) # E: No overload variant
|
||||
np.corrcoef(AR_f8, ddof=2) # E: No overload variant
|
||||
np.blackman(1j) # E: incompatible type
|
||||
np.bartlett(1j) # E: incompatible type
|
||||
np.hanning(1j) # E: incompatible type
|
||||
np.hamming(1j) # E: incompatible type
|
||||
np.hamming(AR_c16) # E: incompatible type
|
||||
np.kaiser(1j, 1) # E: incompatible type
|
||||
np.sinc(AR_O) # E: incompatible type
|
||||
np.median(AR_M) # E: incompatible type
|
||||
|
||||
np.percentile(AR_f8, 50j) # E: No overload variant
|
||||
np.percentile(AR_f8, 50, interpolation="bob") # E: No overload variant
|
||||
np.quantile(AR_f8, 0.5j) # E: No overload variant
|
||||
np.quantile(AR_f8, 0.5, interpolation="bob") # E: No overload variant
|
||||
np.meshgrid(AR_f8, AR_f8, indexing="bob") # E: incompatible type
|
||||
np.delete(AR_f8, AR_f8) # E: incompatible type
|
||||
np.insert(AR_f8, AR_f8, 1.5) # E: incompatible type
|
||||
np.digitize(AR_f8, 1j) # E: No overload variant
|
@ -0,0 +1,29 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_f8: npt.NDArray[np.float64]
|
||||
AR_c16: npt.NDArray[np.complex128]
|
||||
AR_O: npt.NDArray[np.object_]
|
||||
AR_U: npt.NDArray[np.str_]
|
||||
|
||||
poly_obj: np.poly1d
|
||||
|
||||
np.polymul(AR_f8, AR_U) # E: incompatible type
|
||||
np.polydiv(AR_f8, AR_U) # E: incompatible type
|
||||
|
||||
5**poly_obj # E: No overload variant
|
||||
|
||||
np.polyint(AR_U) # E: incompatible type
|
||||
np.polyint(AR_f8, m=1j) # E: No overload variant
|
||||
|
||||
np.polyder(AR_U) # E: incompatible type
|
||||
np.polyder(AR_f8, m=1j) # E: No overload variant
|
||||
|
||||
np.polyfit(AR_O, AR_f8, 1) # E: incompatible type
|
||||
np.polyfit(AR_f8, AR_f8, 1, rcond=1j) # E: No overload variant
|
||||
np.polyfit(AR_f8, AR_f8, 1, w=AR_c16) # E: incompatible type
|
||||
np.polyfit(AR_f8, AR_f8, 1, cov="bob") # E: No overload variant
|
||||
|
||||
np.polyval(AR_f8, AR_U) # E: incompatible type
|
||||
np.polyadd(AR_f8, AR_U) # E: incompatible type
|
||||
np.polysub(AR_f8, AR_U) # E: incompatible type
|
@ -0,0 +1,3 @@
|
||||
import numpy.lib.array_utils as array_utils
|
||||
|
||||
array_utils.byte_bounds(1) # E: incompatible type
|
@ -0,0 +1,6 @@
|
||||
from numpy.lib import NumpyVersion
|
||||
|
||||
version: NumpyVersion
|
||||
|
||||
NumpyVersion(b"1.8.0") # E: incompatible type
|
||||
version >= b"1.8.0" # E: Unsupported operand types
|
@ -0,0 +1,48 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_f8: npt.NDArray[np.float64]
|
||||
AR_O: npt.NDArray[np.object_]
|
||||
AR_M: npt.NDArray[np.datetime64]
|
||||
|
||||
np.linalg.tensorsolve(AR_O, AR_O) # E: incompatible type
|
||||
|
||||
np.linalg.solve(AR_O, AR_O) # E: incompatible type
|
||||
|
||||
np.linalg.tensorinv(AR_O) # E: incompatible type
|
||||
|
||||
np.linalg.inv(AR_O) # E: incompatible type
|
||||
|
||||
np.linalg.matrix_power(AR_M, 5) # E: incompatible type
|
||||
|
||||
np.linalg.cholesky(AR_O) # E: incompatible type
|
||||
|
||||
np.linalg.qr(AR_O) # E: incompatible type
|
||||
np.linalg.qr(AR_f8, mode="bob") # E: No overload variant
|
||||
|
||||
np.linalg.eigvals(AR_O) # E: incompatible type
|
||||
|
||||
np.linalg.eigvalsh(AR_O) # E: incompatible type
|
||||
np.linalg.eigvalsh(AR_O, UPLO="bob") # E: No overload variant
|
||||
|
||||
np.linalg.eig(AR_O) # E: incompatible type
|
||||
|
||||
np.linalg.eigh(AR_O) # E: incompatible type
|
||||
np.linalg.eigh(AR_O, UPLO="bob") # E: No overload variant
|
||||
|
||||
np.linalg.svd(AR_O) # E: incompatible type
|
||||
|
||||
np.linalg.cond(AR_O) # E: incompatible type
|
||||
np.linalg.cond(AR_f8, p="bob") # E: incompatible type
|
||||
|
||||
np.linalg.matrix_rank(AR_O) # E: incompatible type
|
||||
|
||||
np.linalg.pinv(AR_O) # E: incompatible type
|
||||
|
||||
np.linalg.slogdet(AR_O) # E: incompatible type
|
||||
|
||||
np.linalg.det(AR_O) # E: incompatible type
|
||||
|
||||
np.linalg.norm(AR_f8, ord="bob") # E: No overload variant
|
||||
|
||||
np.linalg.multi_dot([AR_M]) # E: incompatible type
|
@ -0,0 +1,5 @@
|
||||
import numpy as np
|
||||
|
||||
with open("file.txt", "r") as f:
|
||||
np.memmap(f) # E: No overload variant
|
||||
np.memmap("test.txt", shape=[10, 5]) # E: No overload variant
|
@ -0,0 +1,18 @@
|
||||
import numpy as np
|
||||
|
||||
np.testing.bob # E: Module has no attribute
|
||||
np.bob # E: Module has no attribute
|
||||
|
||||
# Stdlib modules in the namespace by accident
|
||||
np.warnings # E: Module has no attribute
|
||||
np.sys # E: Module has no attribute
|
||||
np.os # E: Module "numpy" does not explicitly export
|
||||
np.math # E: Module has no attribute
|
||||
|
||||
# Public sub-modules that are not imported to their parent module by default;
|
||||
# e.g. one must first execute `import numpy.lib.recfunctions`
|
||||
np.lib.recfunctions # E: Module has no attribute
|
||||
|
||||
np.__NUMPY_SETUP__ # E: Module has no attribute
|
||||
np.__deprecated_attrs__ # E: Module has no attribute
|
||||
np.__expired_functions__ # E: Module has no attribute
|
@ -0,0 +1,53 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
i8: np.int64
|
||||
|
||||
AR_b: npt.NDArray[np.bool]
|
||||
AR_u1: npt.NDArray[np.uint8]
|
||||
AR_i8: npt.NDArray[np.int64]
|
||||
AR_f8: npt.NDArray[np.float64]
|
||||
AR_M: npt.NDArray[np.datetime64]
|
||||
|
||||
M: np.datetime64
|
||||
|
||||
AR_LIKE_f: list[float]
|
||||
|
||||
def func(a: int) -> None: ...
|
||||
|
||||
np.where(AR_b, 1) # E: No overload variant
|
||||
|
||||
np.can_cast(AR_f8, 1) # E: incompatible type
|
||||
|
||||
np.vdot(AR_M, AR_M) # E: incompatible type
|
||||
|
||||
np.copyto(AR_LIKE_f, AR_f8) # E: incompatible type
|
||||
|
||||
np.putmask(AR_LIKE_f, [True, True, False], 1.5) # E: incompatible type
|
||||
|
||||
np.packbits(AR_f8) # E: incompatible type
|
||||
np.packbits(AR_u1, bitorder=">") # E: incompatible type
|
||||
|
||||
np.unpackbits(AR_i8) # E: incompatible type
|
||||
np.unpackbits(AR_u1, bitorder=">") # E: incompatible type
|
||||
|
||||
np.shares_memory(1, 1, max_work=i8) # E: incompatible type
|
||||
np.may_share_memory(1, 1, max_work=i8) # E: incompatible type
|
||||
|
||||
np.arange(M) # E: No overload variant
|
||||
np.arange(stop=10) # E: No overload variant
|
||||
|
||||
np.datetime_data(int) # E: incompatible type
|
||||
|
||||
np.busday_offset("2012", 10) # E: No overload variant
|
||||
|
||||
np.datetime_as_string("2012") # E: No overload variant
|
||||
|
||||
np.char.compare_chararrays("a", b"a", "==", False) # E: No overload variant
|
||||
|
||||
np.nested_iters([AR_i8, AR_i8]) # E: Missing positional argument
|
||||
np.nested_iters([AR_i8, AR_i8], 0) # E: incompatible type
|
||||
np.nested_iters([AR_i8, AR_i8], [0]) # E: incompatible type
|
||||
np.nested_iters([AR_i8, AR_i8], [[0], [1]], flags=["test"]) # E: incompatible type
|
||||
np.nested_iters([AR_i8, AR_i8], [[0], [1]], op_flags=[["test"]]) # E: incompatible type
|
||||
np.nested_iters([AR_i8, AR_i8], [[0], [1]], buffersize=1.0) # E: incompatible type
|
@ -0,0 +1,11 @@
|
||||
import numpy as np
|
||||
|
||||
# Ban setting dtype since mutating the type of the array in place
|
||||
# makes having ndarray be generic over dtype impossible. Generally
|
||||
# users should use `ndarray.view` in this situation anyway. See
|
||||
#
|
||||
# https://github.com/numpy/numpy-stubs/issues/7
|
||||
#
|
||||
# for more context.
|
||||
float_array = np.array([1.0])
|
||||
float_array.dtype = np.bool # E: Property "dtype" defined in "ndarray" is read-only
|
@ -0,0 +1,43 @@
|
||||
"""
|
||||
Tests for miscellaneous (non-magic) ``np.ndarray``/``np.generic`` methods.
|
||||
|
||||
More extensive tests are performed for the methods'
|
||||
function-based counterpart in `../from_numeric.py`.
|
||||
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
f8: np.float64
|
||||
AR_f8: npt.NDArray[np.float64]
|
||||
AR_M: npt.NDArray[np.datetime64]
|
||||
AR_b: npt.NDArray[np.bool]
|
||||
|
||||
ctypes_obj = AR_f8.ctypes
|
||||
|
||||
reveal_type(ctypes_obj.get_data()) # E: has no attribute
|
||||
reveal_type(ctypes_obj.get_shape()) # E: has no attribute
|
||||
reveal_type(ctypes_obj.get_strides()) # E: has no attribute
|
||||
reveal_type(ctypes_obj.get_as_parameter()) # E: has no attribute
|
||||
|
||||
f8.argpartition(0) # E: has no attribute
|
||||
f8.diagonal() # E: has no attribute
|
||||
f8.dot(1) # E: has no attribute
|
||||
f8.nonzero() # E: has no attribute
|
||||
f8.partition(0) # E: has no attribute
|
||||
f8.put(0, 2) # E: has no attribute
|
||||
f8.setfield(2, np.float64) # E: has no attribute
|
||||
f8.sort() # E: has no attribute
|
||||
f8.trace() # E: has no attribute
|
||||
|
||||
AR_M.__int__() # E: Invalid self argument
|
||||
AR_M.__float__() # E: Invalid self argument
|
||||
AR_M.__complex__() # E: Invalid self argument
|
||||
AR_b.__index__() # E: Invalid self argument
|
||||
|
||||
AR_f8[1.5] # E: No overload variant
|
||||
AR_f8["field_a"] # E: No overload variant
|
||||
AR_f8[["field_a", "field_b"]] # E: Invalid index type
|
||||
|
||||
AR_f8.__array_finalize__(object()) # E: incompatible type
|
@ -0,0 +1,8 @@
|
||||
import numpy as np
|
||||
|
||||
class Test(np.nditer): ... # E: Cannot inherit from final class
|
||||
|
||||
np.nditer([0, 1], flags=["test"]) # E: incompatible type
|
||||
np.nditer([0, 1], op_flags=[["test"]]) # E: incompatible type
|
||||
np.nditer([0, 1], itershape=(1.0,)) # E: incompatible type
|
||||
np.nditer([0, 1], buffersize=1.0) # E: incompatible type
|
@ -0,0 +1,17 @@
|
||||
from collections.abc import Sequence
|
||||
from numpy._typing import _NestedSequence
|
||||
|
||||
a: Sequence[float]
|
||||
b: list[complex]
|
||||
c: tuple[str, ...]
|
||||
d: int
|
||||
e: str
|
||||
|
||||
def func(a: _NestedSequence[int]) -> None:
|
||||
...
|
||||
|
||||
reveal_type(func(a)) # E: incompatible type
|
||||
reveal_type(func(b)) # E: incompatible type
|
||||
reveal_type(func(c)) # E: incompatible type
|
||||
reveal_type(func(d)) # E: incompatible type
|
||||
reveal_type(func(e)) # E: incompatible type
|
@ -0,0 +1,23 @@
|
||||
import pathlib
|
||||
from typing import IO
|
||||
|
||||
import numpy.typing as npt
|
||||
import numpy as np
|
||||
|
||||
str_path: str
|
||||
bytes_path: bytes
|
||||
pathlib_path: pathlib.Path
|
||||
str_file: IO[str]
|
||||
AR_i8: npt.NDArray[np.int64]
|
||||
|
||||
np.load(str_file) # E: incompatible type
|
||||
|
||||
np.save(bytes_path, AR_i8) # E: incompatible type
|
||||
|
||||
np.savez(bytes_path, AR_i8) # E: incompatible type
|
||||
|
||||
np.savez_compressed(bytes_path, AR_i8) # E: incompatible type
|
||||
|
||||
np.loadtxt(bytes_path) # E: incompatible type
|
||||
|
||||
np.fromregex(bytes_path, ".", np.int64) # E: No overload variant
|
@ -0,0 +1,5 @@
|
||||
import numpy as np
|
||||
|
||||
np.isdtype(1, np.int64) # E: incompatible type
|
||||
|
||||
np.issubdtype(1, np.int64) # E: incompatible type
|
@ -0,0 +1,62 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
SEED_FLOAT: float = 457.3
|
||||
SEED_ARR_FLOAT: npt.NDArray[np.float64] = np.array([1.0, 2, 3, 4])
|
||||
SEED_ARRLIKE_FLOAT: list[float] = [1.0, 2.0, 3.0, 4.0]
|
||||
SEED_SEED_SEQ: np.random.SeedSequence = np.random.SeedSequence(0)
|
||||
SEED_STR: str = "String seeding not allowed"
|
||||
|
||||
# default rng
|
||||
np.random.default_rng(SEED_FLOAT) # E: incompatible type
|
||||
np.random.default_rng(SEED_ARR_FLOAT) # E: incompatible type
|
||||
np.random.default_rng(SEED_ARRLIKE_FLOAT) # E: incompatible type
|
||||
np.random.default_rng(SEED_STR) # E: incompatible type
|
||||
|
||||
# Seed Sequence
|
||||
np.random.SeedSequence(SEED_FLOAT) # E: incompatible type
|
||||
np.random.SeedSequence(SEED_ARR_FLOAT) # E: incompatible type
|
||||
np.random.SeedSequence(SEED_ARRLIKE_FLOAT) # E: incompatible type
|
||||
np.random.SeedSequence(SEED_SEED_SEQ) # E: incompatible type
|
||||
np.random.SeedSequence(SEED_STR) # E: incompatible type
|
||||
|
||||
seed_seq: np.random.bit_generator.SeedSequence = np.random.SeedSequence()
|
||||
seed_seq.spawn(11.5) # E: incompatible type
|
||||
seed_seq.generate_state(3.14) # E: incompatible type
|
||||
seed_seq.generate_state(3, np.uint8) # E: incompatible type
|
||||
seed_seq.generate_state(3, "uint8") # E: incompatible type
|
||||
seed_seq.generate_state(3, "u1") # E: incompatible type
|
||||
seed_seq.generate_state(3, np.uint16) # E: incompatible type
|
||||
seed_seq.generate_state(3, "uint16") # E: incompatible type
|
||||
seed_seq.generate_state(3, "u2") # E: incompatible type
|
||||
seed_seq.generate_state(3, np.int32) # E: incompatible type
|
||||
seed_seq.generate_state(3, "int32") # E: incompatible type
|
||||
seed_seq.generate_state(3, "i4") # E: incompatible type
|
||||
|
||||
# Bit Generators
|
||||
np.random.MT19937(SEED_FLOAT) # E: incompatible type
|
||||
np.random.MT19937(SEED_ARR_FLOAT) # E: incompatible type
|
||||
np.random.MT19937(SEED_ARRLIKE_FLOAT) # E: incompatible type
|
||||
np.random.MT19937(SEED_STR) # E: incompatible type
|
||||
|
||||
np.random.PCG64(SEED_FLOAT) # E: incompatible type
|
||||
np.random.PCG64(SEED_ARR_FLOAT) # E: incompatible type
|
||||
np.random.PCG64(SEED_ARRLIKE_FLOAT) # E: incompatible type
|
||||
np.random.PCG64(SEED_STR) # E: incompatible type
|
||||
|
||||
np.random.Philox(SEED_FLOAT) # E: incompatible type
|
||||
np.random.Philox(SEED_ARR_FLOAT) # E: incompatible type
|
||||
np.random.Philox(SEED_ARRLIKE_FLOAT) # E: incompatible type
|
||||
np.random.Philox(SEED_STR) # E: incompatible type
|
||||
|
||||
np.random.SFC64(SEED_FLOAT) # E: incompatible type
|
||||
np.random.SFC64(SEED_ARR_FLOAT) # E: incompatible type
|
||||
np.random.SFC64(SEED_ARRLIKE_FLOAT) # E: incompatible type
|
||||
np.random.SFC64(SEED_STR) # E: incompatible type
|
||||
|
||||
# Generator
|
||||
np.random.Generator(None) # E: incompatible type
|
||||
np.random.Generator(12333283902830213) # E: incompatible type
|
||||
np.random.Generator("OxFEEDF00D") # E: incompatible type
|
||||
np.random.Generator([123, 234]) # E: incompatible type
|
||||
np.random.Generator(np.array([123, 234], dtype="u4")) # E: incompatible type
|
@ -0,0 +1,17 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_i8: npt.NDArray[np.int64]
|
||||
|
||||
np.rec.fromarrays(1) # E: No overload variant
|
||||
np.rec.fromarrays([1, 2, 3], dtype=[("f8", "f8")], formats=["f8", "f8"]) # E: No overload variant
|
||||
|
||||
np.rec.fromrecords(AR_i8) # E: incompatible type
|
||||
np.rec.fromrecords([(1.5,)], dtype=[("f8", "f8")], formats=["f8", "f8"]) # E: No overload variant
|
||||
|
||||
np.rec.fromstring("string", dtype=[("f8", "f8")]) # E: No overload variant
|
||||
np.rec.fromstring(b"bytes") # E: No overload variant
|
||||
np.rec.fromstring(b"(1.5,)", dtype=[("f8", "f8")], formats=["f8", "f8"]) # E: No overload variant
|
||||
|
||||
with open("test", "r") as f:
|
||||
np.rec.fromfile(f, dtype=[("f8", "f8")]) # E: No overload variant
|
@ -0,0 +1,92 @@
|
||||
import sys
|
||||
import numpy as np
|
||||
|
||||
f2: np.float16
|
||||
f8: np.float64
|
||||
c8: np.complex64
|
||||
|
||||
# Construction
|
||||
|
||||
np.float32(3j) # E: incompatible type
|
||||
|
||||
# Technically the following examples are valid NumPy code. But they
|
||||
# are not considered a best practice, and people who wish to use the
|
||||
# stubs should instead do
|
||||
#
|
||||
# np.array([1.0, 0.0, 0.0], dtype=np.float32)
|
||||
# np.array([], dtype=np.complex64)
|
||||
#
|
||||
# See e.g. the discussion on the mailing list
|
||||
#
|
||||
# https://mail.python.org/pipermail/numpy-discussion/2020-April/080566.html
|
||||
#
|
||||
# and the issue
|
||||
#
|
||||
# https://github.com/numpy/numpy-stubs/issues/41
|
||||
#
|
||||
# for more context.
|
||||
np.float32([1.0, 0.0, 0.0]) # E: incompatible type
|
||||
np.complex64([]) # E: incompatible type
|
||||
|
||||
np.complex64(1, 2) # E: Too many arguments
|
||||
# TODO: protocols (can't check for non-existent protocols w/ __getattr__)
|
||||
|
||||
np.datetime64(0) # E: No overload variant
|
||||
|
||||
class A:
|
||||
def __float__(self):
|
||||
return 1.0
|
||||
|
||||
|
||||
np.int8(A()) # E: incompatible type
|
||||
np.int16(A()) # E: incompatible type
|
||||
np.int32(A()) # E: incompatible type
|
||||
np.int64(A()) # E: incompatible type
|
||||
np.uint8(A()) # E: incompatible type
|
||||
np.uint16(A()) # E: incompatible type
|
||||
np.uint32(A()) # E: incompatible type
|
||||
np.uint64(A()) # E: incompatible type
|
||||
|
||||
np.void("test") # E: No overload variant
|
||||
np.void("test", dtype=None) # E: No overload variant
|
||||
|
||||
np.generic(1) # E: Cannot instantiate abstract class
|
||||
np.number(1) # E: Cannot instantiate abstract class
|
||||
np.integer(1) # E: Cannot instantiate abstract class
|
||||
np.inexact(1) # E: Cannot instantiate abstract class
|
||||
np.character("test") # E: Cannot instantiate abstract class
|
||||
np.flexible(b"test") # E: Cannot instantiate abstract class
|
||||
|
||||
np.float64(value=0.0) # E: Unexpected keyword argument
|
||||
np.int64(value=0) # E: Unexpected keyword argument
|
||||
np.uint64(value=0) # E: Unexpected keyword argument
|
||||
np.complex128(value=0.0j) # E: Unexpected keyword argument
|
||||
np.str_(value='bob') # E: No overload variant
|
||||
np.bytes_(value=b'test') # E: No overload variant
|
||||
np.void(value=b'test') # E: No overload variant
|
||||
np.bool(value=True) # E: Unexpected keyword argument
|
||||
np.datetime64(value="2019") # E: No overload variant
|
||||
np.timedelta64(value=0) # E: Unexpected keyword argument
|
||||
|
||||
np.bytes_(b"hello", encoding='utf-8') # E: No overload variant
|
||||
np.str_("hello", encoding='utf-8') # E: No overload variant
|
||||
|
||||
f8.item(1) # E: incompatible type
|
||||
f8.item((0, 1)) # E: incompatible type
|
||||
f8.squeeze(axis=1) # E: incompatible type
|
||||
f8.squeeze(axis=(0, 1)) # E: incompatible type
|
||||
f8.transpose(1) # E: incompatible type
|
||||
|
||||
def func(a: np.float32) -> None: ...
|
||||
|
||||
func(f2) # E: incompatible type
|
||||
func(f8) # E: incompatible type
|
||||
|
||||
round(c8) # E: No overload variant
|
||||
|
||||
c8.__getnewargs__() # E: Invalid self argument
|
||||
f2.__getnewargs__() # E: Invalid self argument
|
||||
f2.hex() # E: Invalid self argument
|
||||
np.float16.fromhex("0x0.0p+0") # E: Invalid self argument
|
||||
f2.__trunc__() # E: Invalid self argument
|
||||
f2.__getformat__("float") # E: Invalid self argument
|
@ -0,0 +1,6 @@
|
||||
from typing import Any
|
||||
import numpy as np
|
||||
|
||||
# test bounds of _ShapeType_co
|
||||
|
||||
np.ndarray[tuple[str, str], Any] # E: Value of type variable
|
@ -0,0 +1,8 @@
|
||||
import numpy as np
|
||||
|
||||
class DTypeLike:
|
||||
dtype: np.dtype[np.int_]
|
||||
|
||||
dtype_like: DTypeLike
|
||||
|
||||
np.expand_dims(dtype_like, (5, 10)) # E: No overload variant
|
@ -0,0 +1,9 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_f8: npt.NDArray[np.float64]
|
||||
|
||||
np.lib.stride_tricks.as_strided(AR_f8, shape=8) # E: No overload variant
|
||||
np.lib.stride_tricks.as_strided(AR_f8, strides=8) # E: No overload variant
|
||||
|
||||
np.lib.stride_tricks.sliding_window_view(AR_f8, axis=(1,)) # E: No overload variant
|
@ -0,0 +1,69 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_U: npt.NDArray[np.str_]
|
||||
AR_S: npt.NDArray[np.bytes_]
|
||||
|
||||
np.strings.equal(AR_U, AR_S) # E: incompatible type
|
||||
|
||||
np.strings.not_equal(AR_U, AR_S) # E: incompatible type
|
||||
|
||||
np.strings.greater_equal(AR_U, AR_S) # E: incompatible type
|
||||
|
||||
np.strings.less_equal(AR_U, AR_S) # E: incompatible type
|
||||
|
||||
np.strings.greater(AR_U, AR_S) # E: incompatible type
|
||||
|
||||
np.strings.less(AR_U, AR_S) # E: incompatible type
|
||||
|
||||
np.strings.encode(AR_S) # E: incompatible type
|
||||
np.strings.decode(AR_U) # E: incompatible type
|
||||
|
||||
np.strings.join(AR_U, b"_") # E: incompatible type
|
||||
np.strings.join(AR_S, "_") # E: incompatible type
|
||||
|
||||
np.strings.ljust(AR_U, 5, fillchar=b"a") # E: incompatible type
|
||||
np.strings.ljust(AR_S, 5, fillchar="a") # E: incompatible type
|
||||
np.strings.rjust(AR_U, 5, fillchar=b"a") # E: incompatible type
|
||||
np.strings.rjust(AR_S, 5, fillchar="a") # E: incompatible type
|
||||
|
||||
np.strings.lstrip(AR_U, b"a") # E: incompatible type
|
||||
np.strings.lstrip(AR_S, "a") # E: incompatible type
|
||||
np.strings.strip(AR_U, b"a") # E: incompatible type
|
||||
np.strings.strip(AR_S, "a") # E: incompatible type
|
||||
np.strings.rstrip(AR_U, b"a") # E: incompatible type
|
||||
np.strings.rstrip(AR_S, "a") # E: incompatible type
|
||||
|
||||
np.strings.partition(AR_U, b"a") # E: incompatible type
|
||||
np.strings.partition(AR_S, "a") # E: incompatible type
|
||||
np.strings.rpartition(AR_U, b"a") # E: incompatible type
|
||||
np.strings.rpartition(AR_S, "a") # E: incompatible type
|
||||
|
||||
np.strings.split(AR_U, b"_") # E: incompatible type
|
||||
np.strings.split(AR_S, "_") # E: incompatible type
|
||||
np.strings.rsplit(AR_U, b"_") # E: incompatible type
|
||||
np.strings.rsplit(AR_S, "_") # E: incompatible type
|
||||
|
||||
np.strings.count(AR_U, b"a", [1, 2, 3], [1, 2, 3]) # E: incompatible type
|
||||
np.strings.count(AR_S, "a", 0, 9) # E: incompatible type
|
||||
|
||||
np.strings.endswith(AR_U, b"a", [1, 2, 3], [1, 2, 3]) # E: incompatible type
|
||||
np.strings.endswith(AR_S, "a", 0, 9) # E: incompatible type
|
||||
np.strings.startswith(AR_U, b"a", [1, 2, 3], [1, 2, 3]) # E: incompatible type
|
||||
np.strings.startswith(AR_S, "a", 0, 9) # E: incompatible type
|
||||
|
||||
np.strings.find(AR_U, b"a", [1, 2, 3], [1, 2, 3]) # E: incompatible type
|
||||
np.strings.find(AR_S, "a", 0, 9) # E: incompatible type
|
||||
np.strings.rfind(AR_U, b"a", [1, 2, 3], [1, 2 , 3]) # E: incompatible type
|
||||
np.strings.rfind(AR_S, "a", 0, 9) # E: incompatible type
|
||||
|
||||
np.strings.index(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
np.strings.index(AR_S, "a", end=9) # E: incompatible type
|
||||
np.strings.rindex(AR_U, b"a", start=[1, 2, 3]) # E: incompatible type
|
||||
np.strings.rindex(AR_S, "a", end=9) # E: incompatible type
|
||||
|
||||
np.strings.isdecimal(AR_S) # E: incompatible type
|
||||
np.strings.isnumeric(AR_S) # E: incompatible type
|
||||
|
||||
np.strings.replace(AR_U, b"_", b"-", 10) # E: incompatible type
|
||||
np.strings.replace(AR_S, "_", "-", 1) # E: incompatible type
|
@ -0,0 +1,28 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_U: npt.NDArray[np.str_]
|
||||
|
||||
def func() -> bool: ...
|
||||
|
||||
np.testing.assert_(True, msg=1) # E: incompatible type
|
||||
np.testing.build_err_msg(1, "test") # E: incompatible type
|
||||
np.testing.assert_almost_equal(AR_U, AR_U) # E: incompatible type
|
||||
np.testing.assert_approx_equal([1, 2, 3], [1, 2, 3]) # E: incompatible type
|
||||
np.testing.assert_array_almost_equal(AR_U, AR_U) # E: incompatible type
|
||||
np.testing.assert_array_less(AR_U, AR_U) # E: incompatible type
|
||||
np.testing.assert_string_equal(b"a", b"a") # E: incompatible type
|
||||
|
||||
np.testing.assert_raises(expected_exception=TypeError, callable=func) # E: No overload variant
|
||||
np.testing.assert_raises_regex(expected_exception=TypeError, expected_regex="T", callable=func) # E: No overload variant
|
||||
|
||||
np.testing.assert_allclose(AR_U, AR_U) # E: incompatible type
|
||||
np.testing.assert_array_almost_equal_nulp(AR_U, AR_U) # E: incompatible type
|
||||
np.testing.assert_array_max_ulp(AR_U, AR_U) # E: incompatible type
|
||||
|
||||
np.testing.assert_warns(warning_class=RuntimeWarning, func=func) # E: No overload variant
|
||||
np.testing.assert_no_warnings(func=func) # E: No overload variant
|
||||
np.testing.assert_no_warnings(func, None) # E: Too many arguments
|
||||
np.testing.assert_no_warnings(func, test=None) # E: Unexpected keyword argument
|
||||
|
||||
np.testing.assert_no_gc_cycles(func=func) # E: No overload variant
|
@ -0,0 +1,37 @@
|
||||
from typing import Any, TypeVar
|
||||
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
|
||||
def func1(ar: npt.NDArray[Any], a: int) -> npt.NDArray[np.str_]:
|
||||
pass
|
||||
|
||||
|
||||
def func2(ar: npt.NDArray[Any], a: float) -> float:
|
||||
pass
|
||||
|
||||
|
||||
AR_b: npt.NDArray[np.bool]
|
||||
AR_m: npt.NDArray[np.timedelta64]
|
||||
|
||||
AR_LIKE_b: list[bool]
|
||||
|
||||
np.eye(10, M=20.0) # E: No overload variant
|
||||
np.eye(10, k=2.5, dtype=int) # E: No overload variant
|
||||
|
||||
np.diag(AR_b, k=0.5) # E: No overload variant
|
||||
np.diagflat(AR_b, k=0.5) # E: No overload variant
|
||||
|
||||
np.tri(10, M=20.0) # E: No overload variant
|
||||
np.tri(10, k=2.5, dtype=int) # E: No overload variant
|
||||
|
||||
np.tril(AR_b, k=0.5) # E: No overload variant
|
||||
np.triu(AR_b, k=0.5) # E: No overload variant
|
||||
|
||||
np.vander(AR_m) # E: incompatible type
|
||||
|
||||
np.histogram2d(AR_m) # E: No overload variant
|
||||
|
||||
np.mask_indices(10, func1) # E: incompatible type
|
||||
np.mask_indices(10, func2, 10.5) # E: incompatible type
|
@ -0,0 +1,13 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
DTYPE_i8: np.dtype[np.int64]
|
||||
|
||||
np.mintypecode(DTYPE_i8) # E: incompatible type
|
||||
np.iscomplexobj(DTYPE_i8) # E: incompatible type
|
||||
np.isrealobj(DTYPE_i8) # E: incompatible type
|
||||
|
||||
np.typename(DTYPE_i8) # E: No overload variant
|
||||
np.typename("invalid") # E: No overload variant
|
||||
|
||||
np.common_type(np.timedelta64()) # E: incompatible type
|
@ -0,0 +1,21 @@
|
||||
"""Typing tests for `numpy._core._ufunc_config`."""
|
||||
|
||||
import numpy as np
|
||||
|
||||
def func1(a: str, b: int, c: float) -> None: ...
|
||||
def func2(a: str, *, b: int) -> None: ...
|
||||
|
||||
class Write1:
|
||||
def write1(self, a: str) -> None: ...
|
||||
|
||||
class Write2:
|
||||
def write(self, a: str, b: str) -> None: ...
|
||||
|
||||
class Write3:
|
||||
def write(self, *, a: str) -> None: ...
|
||||
|
||||
np.seterrcall(func1) # E: Argument 1 to "seterrcall" has incompatible type
|
||||
np.seterrcall(func2) # E: Argument 1 to "seterrcall" has incompatible type
|
||||
np.seterrcall(Write1()) # E: Argument 1 to "seterrcall" has incompatible type
|
||||
np.seterrcall(Write2()) # E: Argument 1 to "seterrcall" has incompatible type
|
||||
np.seterrcall(Write3()) # E: Argument 1 to "seterrcall" has incompatible type
|
@ -0,0 +1,21 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_c: npt.NDArray[np.complex128]
|
||||
AR_m: npt.NDArray[np.timedelta64]
|
||||
AR_M: npt.NDArray[np.datetime64]
|
||||
AR_O: npt.NDArray[np.object_]
|
||||
|
||||
np.fix(AR_c) # E: incompatible type
|
||||
np.fix(AR_m) # E: incompatible type
|
||||
np.fix(AR_M) # E: incompatible type
|
||||
|
||||
np.isposinf(AR_c) # E: incompatible type
|
||||
np.isposinf(AR_m) # E: incompatible type
|
||||
np.isposinf(AR_M) # E: incompatible type
|
||||
np.isposinf(AR_O) # E: incompatible type
|
||||
|
||||
np.isneginf(AR_c) # E: incompatible type
|
||||
np.isneginf(AR_m) # E: incompatible type
|
||||
np.isneginf(AR_M) # E: incompatible type
|
||||
np.isneginf(AR_O) # E: incompatible type
|
@ -0,0 +1,17 @@
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
AR_f8: npt.NDArray[np.float64]
|
||||
|
||||
np.sin.nin + "foo" # E: Unsupported operand types
|
||||
np.sin(1, foo="bar") # E: No overload variant
|
||||
|
||||
np.abs(None) # E: No overload variant
|
||||
|
||||
np.add(1, 1, 1) # E: No overload variant
|
||||
np.add(1, 1, axis=0) # E: No overload variant
|
||||
|
||||
np.matmul(AR_f8, AR_f8, where=True) # E: No overload variant
|
||||
|
||||
np.frexp(AR_f8, out=None) # E: No overload variant
|
||||
np.frexp(AR_f8, out=AR_f8) # E: No overload variant
|
@ -0,0 +1,5 @@
|
||||
import numpy.exceptions as ex
|
||||
|
||||
ex.AxisError(1.0) # E: No overload variant
|
||||
ex.AxisError(1, ndim=2.0) # E: No overload variant
|
||||
ex.AxisError(2, msg_prefix=404) # E: No overload variant
|
@ -0,0 +1,25 @@
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
from numpy._typing import _80Bit, _96Bit, _128Bit, _256Bit
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
from typing import assert_type
|
||||
else:
|
||||
from typing_extensions import assert_type
|
||||
|
||||
assert_type(np.uint128(), np.unsignedinteger[_128Bit])
|
||||
assert_type(np.uint256(), np.unsignedinteger[_256Bit])
|
||||
|
||||
assert_type(np.int128(), np.signedinteger[_128Bit])
|
||||
assert_type(np.int256(), np.signedinteger[_256Bit])
|
||||
|
||||
assert_type(np.float80(), np.floating[_80Bit])
|
||||
assert_type(np.float96(), np.floating[_96Bit])
|
||||
assert_type(np.float128(), np.floating[_128Bit])
|
||||
assert_type(np.float256(), np.floating[_256Bit])
|
||||
|
||||
assert_type(np.complex160(), np.complexfloating[_80Bit, _80Bit])
|
||||
assert_type(np.complex192(), np.complexfloating[_96Bit, _96Bit])
|
||||
assert_type(np.complex256(), np.complexfloating[_128Bit, _128Bit])
|
||||
assert_type(np.complex512(), np.complexfloating[_256Bit, _256Bit])
|
@ -0,0 +1,7 @@
|
||||
[mypy]
|
||||
plugins = numpy.typing.mypy_plugin
|
||||
show_absolute_path = True
|
||||
implicit_reexport = False
|
||||
pretty = True
|
||||
disallow_any_unimported = True
|
||||
disallow_any_generics = True
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,595 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
c16 = np.complex128(1)
|
||||
f8 = np.float64(1)
|
||||
i8 = np.int64(1)
|
||||
u8 = np.uint64(1)
|
||||
|
||||
c8 = np.complex64(1)
|
||||
f4 = np.float32(1)
|
||||
i4 = np.int32(1)
|
||||
u4 = np.uint32(1)
|
||||
|
||||
dt = np.datetime64(1, "D")
|
||||
td = np.timedelta64(1, "D")
|
||||
|
||||
b_ = np.bool(1)
|
||||
|
||||
b = bool(1)
|
||||
c = complex(1)
|
||||
f = float(1)
|
||||
i = int(1)
|
||||
|
||||
|
||||
class Object:
|
||||
def __array__(self, dtype: np.typing.DTypeLike = None,
|
||||
copy: bool | None = None) -> np.ndarray[Any, np.dtype[np.object_]]:
|
||||
ret = np.empty((), dtype=object)
|
||||
ret[()] = self
|
||||
return ret
|
||||
|
||||
def __sub__(self, value: Any) -> Object:
|
||||
return self
|
||||
|
||||
def __rsub__(self, value: Any) -> Object:
|
||||
return self
|
||||
|
||||
def __floordiv__(self, value: Any) -> Object:
|
||||
return self
|
||||
|
||||
def __rfloordiv__(self, value: Any) -> Object:
|
||||
return self
|
||||
|
||||
def __mul__(self, value: Any) -> Object:
|
||||
return self
|
||||
|
||||
def __rmul__(self, value: Any) -> Object:
|
||||
return self
|
||||
|
||||
def __pow__(self, value: Any) -> Object:
|
||||
return self
|
||||
|
||||
def __rpow__(self, value: Any) -> Object:
|
||||
return self
|
||||
|
||||
|
||||
AR_b: np.ndarray[Any, np.dtype[np.bool]] = np.array([True])
|
||||
AR_u: np.ndarray[Any, np.dtype[np.uint32]] = np.array([1], dtype=np.uint32)
|
||||
AR_i: np.ndarray[Any, np.dtype[np.int64]] = np.array([1])
|
||||
AR_f: np.ndarray[Any, np.dtype[np.float64]] = np.array([1.0])
|
||||
AR_c: np.ndarray[Any, np.dtype[np.complex128]] = np.array([1j])
|
||||
AR_m: np.ndarray[Any, np.dtype[np.timedelta64]] = np.array([np.timedelta64(1, "D")])
|
||||
AR_M: np.ndarray[Any, np.dtype[np.datetime64]] = np.array([np.datetime64(1, "D")])
|
||||
AR_O: np.ndarray[Any, np.dtype[np.object_]] = np.array([Object()])
|
||||
|
||||
AR_LIKE_b = [True]
|
||||
AR_LIKE_u = [np.uint32(1)]
|
||||
AR_LIKE_i = [1]
|
||||
AR_LIKE_f = [1.0]
|
||||
AR_LIKE_c = [1j]
|
||||
AR_LIKE_m = [np.timedelta64(1, "D")]
|
||||
AR_LIKE_M = [np.datetime64(1, "D")]
|
||||
AR_LIKE_O = [Object()]
|
||||
|
||||
# Array subtractions
|
||||
|
||||
AR_b - AR_LIKE_u
|
||||
AR_b - AR_LIKE_i
|
||||
AR_b - AR_LIKE_f
|
||||
AR_b - AR_LIKE_c
|
||||
AR_b - AR_LIKE_m
|
||||
AR_b - AR_LIKE_O
|
||||
|
||||
AR_LIKE_u - AR_b
|
||||
AR_LIKE_i - AR_b
|
||||
AR_LIKE_f - AR_b
|
||||
AR_LIKE_c - AR_b
|
||||
AR_LIKE_m - AR_b
|
||||
AR_LIKE_M - AR_b
|
||||
AR_LIKE_O - AR_b
|
||||
|
||||
AR_u - AR_LIKE_b
|
||||
AR_u - AR_LIKE_u
|
||||
AR_u - AR_LIKE_i
|
||||
AR_u - AR_LIKE_f
|
||||
AR_u - AR_LIKE_c
|
||||
AR_u - AR_LIKE_m
|
||||
AR_u - AR_LIKE_O
|
||||
|
||||
AR_LIKE_b - AR_u
|
||||
AR_LIKE_u - AR_u
|
||||
AR_LIKE_i - AR_u
|
||||
AR_LIKE_f - AR_u
|
||||
AR_LIKE_c - AR_u
|
||||
AR_LIKE_m - AR_u
|
||||
AR_LIKE_M - AR_u
|
||||
AR_LIKE_O - AR_u
|
||||
|
||||
AR_i - AR_LIKE_b
|
||||
AR_i - AR_LIKE_u
|
||||
AR_i - AR_LIKE_i
|
||||
AR_i - AR_LIKE_f
|
||||
AR_i - AR_LIKE_c
|
||||
AR_i - AR_LIKE_m
|
||||
AR_i - AR_LIKE_O
|
||||
|
||||
AR_LIKE_b - AR_i
|
||||
AR_LIKE_u - AR_i
|
||||
AR_LIKE_i - AR_i
|
||||
AR_LIKE_f - AR_i
|
||||
AR_LIKE_c - AR_i
|
||||
AR_LIKE_m - AR_i
|
||||
AR_LIKE_M - AR_i
|
||||
AR_LIKE_O - AR_i
|
||||
|
||||
AR_f - AR_LIKE_b
|
||||
AR_f - AR_LIKE_u
|
||||
AR_f - AR_LIKE_i
|
||||
AR_f - AR_LIKE_f
|
||||
AR_f - AR_LIKE_c
|
||||
AR_f - AR_LIKE_O
|
||||
|
||||
AR_LIKE_b - AR_f
|
||||
AR_LIKE_u - AR_f
|
||||
AR_LIKE_i - AR_f
|
||||
AR_LIKE_f - AR_f
|
||||
AR_LIKE_c - AR_f
|
||||
AR_LIKE_O - AR_f
|
||||
|
||||
AR_c - AR_LIKE_b
|
||||
AR_c - AR_LIKE_u
|
||||
AR_c - AR_LIKE_i
|
||||
AR_c - AR_LIKE_f
|
||||
AR_c - AR_LIKE_c
|
||||
AR_c - AR_LIKE_O
|
||||
|
||||
AR_LIKE_b - AR_c
|
||||
AR_LIKE_u - AR_c
|
||||
AR_LIKE_i - AR_c
|
||||
AR_LIKE_f - AR_c
|
||||
AR_LIKE_c - AR_c
|
||||
AR_LIKE_O - AR_c
|
||||
|
||||
AR_m - AR_LIKE_b
|
||||
AR_m - AR_LIKE_u
|
||||
AR_m - AR_LIKE_i
|
||||
AR_m - AR_LIKE_m
|
||||
|
||||
AR_LIKE_b - AR_m
|
||||
AR_LIKE_u - AR_m
|
||||
AR_LIKE_i - AR_m
|
||||
AR_LIKE_m - AR_m
|
||||
AR_LIKE_M - AR_m
|
||||
|
||||
AR_M - AR_LIKE_b
|
||||
AR_M - AR_LIKE_u
|
||||
AR_M - AR_LIKE_i
|
||||
AR_M - AR_LIKE_m
|
||||
AR_M - AR_LIKE_M
|
||||
|
||||
AR_LIKE_M - AR_M
|
||||
|
||||
AR_O - AR_LIKE_b
|
||||
AR_O - AR_LIKE_u
|
||||
AR_O - AR_LIKE_i
|
||||
AR_O - AR_LIKE_f
|
||||
AR_O - AR_LIKE_c
|
||||
AR_O - AR_LIKE_O
|
||||
|
||||
AR_LIKE_b - AR_O
|
||||
AR_LIKE_u - AR_O
|
||||
AR_LIKE_i - AR_O
|
||||
AR_LIKE_f - AR_O
|
||||
AR_LIKE_c - AR_O
|
||||
AR_LIKE_O - AR_O
|
||||
|
||||
AR_u += AR_b
|
||||
AR_u += AR_u
|
||||
AR_u += 1 # Allowed during runtime as long as the object is 0D and >=0
|
||||
|
||||
# Array floor division
|
||||
|
||||
AR_b // AR_LIKE_b
|
||||
AR_b // AR_LIKE_u
|
||||
AR_b // AR_LIKE_i
|
||||
AR_b // AR_LIKE_f
|
||||
AR_b // AR_LIKE_O
|
||||
|
||||
AR_LIKE_b // AR_b
|
||||
AR_LIKE_u // AR_b
|
||||
AR_LIKE_i // AR_b
|
||||
AR_LIKE_f // AR_b
|
||||
AR_LIKE_O // AR_b
|
||||
|
||||
AR_u // AR_LIKE_b
|
||||
AR_u // AR_LIKE_u
|
||||
AR_u // AR_LIKE_i
|
||||
AR_u // AR_LIKE_f
|
||||
AR_u // AR_LIKE_O
|
||||
|
||||
AR_LIKE_b // AR_u
|
||||
AR_LIKE_u // AR_u
|
||||
AR_LIKE_i // AR_u
|
||||
AR_LIKE_f // AR_u
|
||||
AR_LIKE_m // AR_u
|
||||
AR_LIKE_O // AR_u
|
||||
|
||||
AR_i // AR_LIKE_b
|
||||
AR_i // AR_LIKE_u
|
||||
AR_i // AR_LIKE_i
|
||||
AR_i // AR_LIKE_f
|
||||
AR_i // AR_LIKE_O
|
||||
|
||||
AR_LIKE_b // AR_i
|
||||
AR_LIKE_u // AR_i
|
||||
AR_LIKE_i // AR_i
|
||||
AR_LIKE_f // AR_i
|
||||
AR_LIKE_m // AR_i
|
||||
AR_LIKE_O // AR_i
|
||||
|
||||
AR_f // AR_LIKE_b
|
||||
AR_f // AR_LIKE_u
|
||||
AR_f // AR_LIKE_i
|
||||
AR_f // AR_LIKE_f
|
||||
AR_f // AR_LIKE_O
|
||||
|
||||
AR_LIKE_b // AR_f
|
||||
AR_LIKE_u // AR_f
|
||||
AR_LIKE_i // AR_f
|
||||
AR_LIKE_f // AR_f
|
||||
AR_LIKE_m // AR_f
|
||||
AR_LIKE_O // AR_f
|
||||
|
||||
AR_m // AR_LIKE_u
|
||||
AR_m // AR_LIKE_i
|
||||
AR_m // AR_LIKE_f
|
||||
AR_m // AR_LIKE_m
|
||||
|
||||
AR_LIKE_m // AR_m
|
||||
|
||||
AR_O // AR_LIKE_b
|
||||
AR_O // AR_LIKE_u
|
||||
AR_O // AR_LIKE_i
|
||||
AR_O // AR_LIKE_f
|
||||
AR_O // AR_LIKE_O
|
||||
|
||||
AR_LIKE_b // AR_O
|
||||
AR_LIKE_u // AR_O
|
||||
AR_LIKE_i // AR_O
|
||||
AR_LIKE_f // AR_O
|
||||
AR_LIKE_O // AR_O
|
||||
|
||||
# Inplace multiplication
|
||||
|
||||
AR_b *= AR_LIKE_b
|
||||
|
||||
AR_u *= AR_LIKE_b
|
||||
AR_u *= AR_LIKE_u
|
||||
|
||||
AR_i *= AR_LIKE_b
|
||||
AR_i *= AR_LIKE_u
|
||||
AR_i *= AR_LIKE_i
|
||||
|
||||
AR_f *= AR_LIKE_b
|
||||
AR_f *= AR_LIKE_u
|
||||
AR_f *= AR_LIKE_i
|
||||
AR_f *= AR_LIKE_f
|
||||
|
||||
AR_c *= AR_LIKE_b
|
||||
AR_c *= AR_LIKE_u
|
||||
AR_c *= AR_LIKE_i
|
||||
AR_c *= AR_LIKE_f
|
||||
AR_c *= AR_LIKE_c
|
||||
|
||||
AR_m *= AR_LIKE_b
|
||||
AR_m *= AR_LIKE_u
|
||||
AR_m *= AR_LIKE_i
|
||||
AR_m *= AR_LIKE_f
|
||||
|
||||
AR_O *= AR_LIKE_b
|
||||
AR_O *= AR_LIKE_u
|
||||
AR_O *= AR_LIKE_i
|
||||
AR_O *= AR_LIKE_f
|
||||
AR_O *= AR_LIKE_c
|
||||
AR_O *= AR_LIKE_O
|
||||
|
||||
# Inplace power
|
||||
|
||||
AR_u **= AR_LIKE_b
|
||||
AR_u **= AR_LIKE_u
|
||||
|
||||
AR_i **= AR_LIKE_b
|
||||
AR_i **= AR_LIKE_u
|
||||
AR_i **= AR_LIKE_i
|
||||
|
||||
AR_f **= AR_LIKE_b
|
||||
AR_f **= AR_LIKE_u
|
||||
AR_f **= AR_LIKE_i
|
||||
AR_f **= AR_LIKE_f
|
||||
|
||||
AR_c **= AR_LIKE_b
|
||||
AR_c **= AR_LIKE_u
|
||||
AR_c **= AR_LIKE_i
|
||||
AR_c **= AR_LIKE_f
|
||||
AR_c **= AR_LIKE_c
|
||||
|
||||
AR_O **= AR_LIKE_b
|
||||
AR_O **= AR_LIKE_u
|
||||
AR_O **= AR_LIKE_i
|
||||
AR_O **= AR_LIKE_f
|
||||
AR_O **= AR_LIKE_c
|
||||
AR_O **= AR_LIKE_O
|
||||
|
||||
# unary ops
|
||||
|
||||
-c16
|
||||
-c8
|
||||
-f8
|
||||
-f4
|
||||
-i8
|
||||
-i4
|
||||
with pytest.warns(RuntimeWarning):
|
||||
-u8
|
||||
-u4
|
||||
-td
|
||||
-AR_f
|
||||
|
||||
+c16
|
||||
+c8
|
||||
+f8
|
||||
+f4
|
||||
+i8
|
||||
+i4
|
||||
+u8
|
||||
+u4
|
||||
+td
|
||||
+AR_f
|
||||
|
||||
abs(c16)
|
||||
abs(c8)
|
||||
abs(f8)
|
||||
abs(f4)
|
||||
abs(i8)
|
||||
abs(i4)
|
||||
abs(u8)
|
||||
abs(u4)
|
||||
abs(td)
|
||||
abs(b_)
|
||||
abs(AR_f)
|
||||
|
||||
# Time structures
|
||||
|
||||
dt + td
|
||||
dt + i
|
||||
dt + i4
|
||||
dt + i8
|
||||
dt - dt
|
||||
dt - i
|
||||
dt - i4
|
||||
dt - i8
|
||||
|
||||
td + td
|
||||
td + i
|
||||
td + i4
|
||||
td + i8
|
||||
td - td
|
||||
td - i
|
||||
td - i4
|
||||
td - i8
|
||||
td / f
|
||||
td / f4
|
||||
td / f8
|
||||
td / td
|
||||
td // td
|
||||
td % td
|
||||
|
||||
|
||||
# boolean
|
||||
|
||||
b_ / b
|
||||
b_ / b_
|
||||
b_ / i
|
||||
b_ / i8
|
||||
b_ / i4
|
||||
b_ / u8
|
||||
b_ / u4
|
||||
b_ / f
|
||||
b_ / f8
|
||||
b_ / f4
|
||||
b_ / c
|
||||
b_ / c16
|
||||
b_ / c8
|
||||
|
||||
b / b_
|
||||
b_ / b_
|
||||
i / b_
|
||||
i8 / b_
|
||||
i4 / b_
|
||||
u8 / b_
|
||||
u4 / b_
|
||||
f / b_
|
||||
f8 / b_
|
||||
f4 / b_
|
||||
c / b_
|
||||
c16 / b_
|
||||
c8 / b_
|
||||
|
||||
# Complex
|
||||
|
||||
c16 + c16
|
||||
c16 + f8
|
||||
c16 + i8
|
||||
c16 + c8
|
||||
c16 + f4
|
||||
c16 + i4
|
||||
c16 + b_
|
||||
c16 + b
|
||||
c16 + c
|
||||
c16 + f
|
||||
c16 + i
|
||||
c16 + AR_f
|
||||
|
||||
c16 + c16
|
||||
f8 + c16
|
||||
i8 + c16
|
||||
c8 + c16
|
||||
f4 + c16
|
||||
i4 + c16
|
||||
b_ + c16
|
||||
b + c16
|
||||
c + c16
|
||||
f + c16
|
||||
i + c16
|
||||
AR_f + c16
|
||||
|
||||
c8 + c16
|
||||
c8 + f8
|
||||
c8 + i8
|
||||
c8 + c8
|
||||
c8 + f4
|
||||
c8 + i4
|
||||
c8 + b_
|
||||
c8 + b
|
||||
c8 + c
|
||||
c8 + f
|
||||
c8 + i
|
||||
c8 + AR_f
|
||||
|
||||
c16 + c8
|
||||
f8 + c8
|
||||
i8 + c8
|
||||
c8 + c8
|
||||
f4 + c8
|
||||
i4 + c8
|
||||
b_ + c8
|
||||
b + c8
|
||||
c + c8
|
||||
f + c8
|
||||
i + c8
|
||||
AR_f + c8
|
||||
|
||||
# Float
|
||||
|
||||
f8 + f8
|
||||
f8 + i8
|
||||
f8 + f4
|
||||
f8 + i4
|
||||
f8 + b_
|
||||
f8 + b
|
||||
f8 + c
|
||||
f8 + f
|
||||
f8 + i
|
||||
f8 + AR_f
|
||||
|
||||
f8 + f8
|
||||
i8 + f8
|
||||
f4 + f8
|
||||
i4 + f8
|
||||
b_ + f8
|
||||
b + f8
|
||||
c + f8
|
||||
f + f8
|
||||
i + f8
|
||||
AR_f + f8
|
||||
|
||||
f4 + f8
|
||||
f4 + i8
|
||||
f4 + f4
|
||||
f4 + i4
|
||||
f4 + b_
|
||||
f4 + b
|
||||
f4 + c
|
||||
f4 + f
|
||||
f4 + i
|
||||
f4 + AR_f
|
||||
|
||||
f8 + f4
|
||||
i8 + f4
|
||||
f4 + f4
|
||||
i4 + f4
|
||||
b_ + f4
|
||||
b + f4
|
||||
c + f4
|
||||
f + f4
|
||||
i + f4
|
||||
AR_f + f4
|
||||
|
||||
# Int
|
||||
|
||||
i8 + i8
|
||||
i8 + u8
|
||||
i8 + i4
|
||||
i8 + u4
|
||||
i8 + b_
|
||||
i8 + b
|
||||
i8 + c
|
||||
i8 + f
|
||||
i8 + i
|
||||
i8 + AR_f
|
||||
|
||||
u8 + u8
|
||||
u8 + i4
|
||||
u8 + u4
|
||||
u8 + b_
|
||||
u8 + b
|
||||
u8 + c
|
||||
u8 + f
|
||||
u8 + i
|
||||
u8 + AR_f
|
||||
|
||||
i8 + i8
|
||||
u8 + i8
|
||||
i4 + i8
|
||||
u4 + i8
|
||||
b_ + i8
|
||||
b + i8
|
||||
c + i8
|
||||
f + i8
|
||||
i + i8
|
||||
AR_f + i8
|
||||
|
||||
u8 + u8
|
||||
i4 + u8
|
||||
u4 + u8
|
||||
b_ + u8
|
||||
b + u8
|
||||
c + u8
|
||||
f + u8
|
||||
i + u8
|
||||
AR_f + u8
|
||||
|
||||
i4 + i8
|
||||
i4 + i4
|
||||
i4 + i
|
||||
i4 + b_
|
||||
i4 + b
|
||||
i4 + AR_f
|
||||
|
||||
u4 + i8
|
||||
u4 + i4
|
||||
u4 + u8
|
||||
u4 + u4
|
||||
u4 + i
|
||||
u4 + b_
|
||||
u4 + b
|
||||
u4 + AR_f
|
||||
|
||||
i8 + i4
|
||||
i4 + i4
|
||||
i + i4
|
||||
b_ + i4
|
||||
b + i4
|
||||
AR_f + i4
|
||||
|
||||
i8 + u4
|
||||
i4 + u4
|
||||
u8 + u4
|
||||
u4 + u4
|
||||
b_ + u4
|
||||
b + u4
|
||||
i + u4
|
||||
AR_f + u4
|
@ -0,0 +1,137 @@
|
||||
from typing import Any
|
||||
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
||||
class Index:
|
||||
def __index__(self) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
class SubClass(npt.NDArray[np.float64]):
|
||||
pass
|
||||
|
||||
|
||||
def func(i: int, j: int, **kwargs: Any) -> SubClass:
|
||||
return B
|
||||
|
||||
|
||||
i8 = np.int64(1)
|
||||
|
||||
A = np.array([1])
|
||||
B = A.view(SubClass).copy()
|
||||
B_stack = np.array([[1], [1]]).view(SubClass)
|
||||
C = [1]
|
||||
|
||||
np.ndarray(Index())
|
||||
np.ndarray([Index()])
|
||||
|
||||
np.array(1, dtype=float)
|
||||
np.array(1, copy=None)
|
||||
np.array(1, order='F')
|
||||
np.array(1, order=None)
|
||||
np.array(1, subok=True)
|
||||
np.array(1, ndmin=3)
|
||||
np.array(1, str, copy=True, order='C', subok=False, ndmin=2)
|
||||
|
||||
np.asarray(A)
|
||||
np.asarray(B)
|
||||
np.asarray(C)
|
||||
|
||||
np.asanyarray(A)
|
||||
np.asanyarray(B)
|
||||
np.asanyarray(B, dtype=int)
|
||||
np.asanyarray(C)
|
||||
|
||||
np.ascontiguousarray(A)
|
||||
np.ascontiguousarray(B)
|
||||
np.ascontiguousarray(C)
|
||||
|
||||
np.asfortranarray(A)
|
||||
np.asfortranarray(B)
|
||||
np.asfortranarray(C)
|
||||
|
||||
np.require(A)
|
||||
np.require(B)
|
||||
np.require(B, dtype=int)
|
||||
np.require(B, requirements=None)
|
||||
np.require(B, requirements="E")
|
||||
np.require(B, requirements=["ENSUREARRAY"])
|
||||
np.require(B, requirements={"F", "E"})
|
||||
np.require(B, requirements=["C", "OWNDATA"])
|
||||
np.require(B, requirements="W")
|
||||
np.require(B, requirements="A")
|
||||
np.require(C)
|
||||
|
||||
np.linspace(0, 2)
|
||||
np.linspace(0.5, [0, 1, 2])
|
||||
np.linspace([0, 1, 2], 3)
|
||||
np.linspace(0j, 2)
|
||||
np.linspace(0, 2, num=10)
|
||||
np.linspace(0, 2, endpoint=True)
|
||||
np.linspace(0, 2, retstep=True)
|
||||
np.linspace(0j, 2j, retstep=True)
|
||||
np.linspace(0, 2, dtype=bool)
|
||||
np.linspace([0, 1], [2, 3], axis=Index())
|
||||
|
||||
np.logspace(0, 2, base=2)
|
||||
np.logspace(0, 2, base=2)
|
||||
np.logspace(0, 2, base=[1j, 2j], num=2)
|
||||
|
||||
np.geomspace(1, 2)
|
||||
|
||||
np.zeros_like(A)
|
||||
np.zeros_like(C)
|
||||
np.zeros_like(B)
|
||||
np.zeros_like(B, dtype=np.int64)
|
||||
|
||||
np.ones_like(A)
|
||||
np.ones_like(C)
|
||||
np.ones_like(B)
|
||||
np.ones_like(B, dtype=np.int64)
|
||||
|
||||
np.empty_like(A)
|
||||
np.empty_like(C)
|
||||
np.empty_like(B)
|
||||
np.empty_like(B, dtype=np.int64)
|
||||
|
||||
np.full_like(A, i8)
|
||||
np.full_like(C, i8)
|
||||
np.full_like(B, i8)
|
||||
np.full_like(B, i8, dtype=np.int64)
|
||||
|
||||
np.ones(1)
|
||||
np.ones([1, 1, 1])
|
||||
|
||||
np.full(1, i8)
|
||||
np.full([1, 1, 1], i8)
|
||||
|
||||
np.indices([1, 2, 3])
|
||||
np.indices([1, 2, 3], sparse=True)
|
||||
|
||||
np.fromfunction(func, (3, 5))
|
||||
|
||||
np.identity(10)
|
||||
|
||||
np.atleast_1d(C)
|
||||
np.atleast_1d(A)
|
||||
np.atleast_1d(C, C)
|
||||
np.atleast_1d(C, A)
|
||||
np.atleast_1d(A, A)
|
||||
|
||||
np.atleast_2d(C)
|
||||
|
||||
np.atleast_3d(C)
|
||||
|
||||
np.vstack([C, C])
|
||||
np.vstack([C, A])
|
||||
np.vstack([A, A])
|
||||
|
||||
np.hstack([C, C])
|
||||
|
||||
np.stack([C, C])
|
||||
np.stack([C, C], axis=0)
|
||||
np.stack([C, C], out=B_stack)
|
||||
|
||||
np.block([[C, C], [C, C]])
|
||||
np.block(A)
|
@ -0,0 +1,43 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import numpy as np
|
||||
from numpy._typing import NDArray, ArrayLike, _SupportsArray
|
||||
|
||||
x1: ArrayLike = True
|
||||
x2: ArrayLike = 5
|
||||
x3: ArrayLike = 1.0
|
||||
x4: ArrayLike = 1 + 1j
|
||||
x5: ArrayLike = np.int8(1)
|
||||
x6: ArrayLike = np.float64(1)
|
||||
x7: ArrayLike = np.complex128(1)
|
||||
x8: ArrayLike = np.array([1, 2, 3])
|
||||
x9: ArrayLike = [1, 2, 3]
|
||||
x10: ArrayLike = (1, 2, 3)
|
||||
x11: ArrayLike = "foo"
|
||||
x12: ArrayLike = memoryview(b'foo')
|
||||
|
||||
|
||||
class A:
|
||||
def __array__(
|
||||
self, dtype: None | np.dtype[Any] = None
|
||||
) -> NDArray[np.float64]:
|
||||
return np.array([1.0, 2.0, 3.0])
|
||||
|
||||
|
||||
x13: ArrayLike = A()
|
||||
|
||||
scalar: _SupportsArray[np.dtype[np.int64]] = np.int64(1)
|
||||
scalar.__array__()
|
||||
array: _SupportsArray[np.dtype[np.int_]] = np.array(1)
|
||||
array.__array__()
|
||||
|
||||
a: _SupportsArray[np.dtype[np.float64]] = A()
|
||||
a.__array__()
|
||||
a.__array__()
|
||||
|
||||
# Escape hatch for when you mean to make something like an object
|
||||
# array.
|
||||
object_array_scalar: object = (i for i in range(10))
|
||||
np.array(object_array_scalar)
|
@ -0,0 +1,37 @@
|
||||
import numpy as np
|
||||
|
||||
AR = np.arange(10)
|
||||
AR.setflags(write=False)
|
||||
|
||||
with np.printoptions():
|
||||
np.set_printoptions(
|
||||
precision=1,
|
||||
threshold=2,
|
||||
edgeitems=3,
|
||||
linewidth=4,
|
||||
suppress=False,
|
||||
nanstr="Bob",
|
||||
infstr="Bill",
|
||||
formatter={},
|
||||
sign="+",
|
||||
floatmode="unique",
|
||||
)
|
||||
np.get_printoptions()
|
||||
str(AR)
|
||||
|
||||
np.array2string(
|
||||
AR,
|
||||
max_line_width=5,
|
||||
precision=2,
|
||||
suppress_small=True,
|
||||
separator=";",
|
||||
prefix="test",
|
||||
threshold=5,
|
||||
floatmode="fixed",
|
||||
suffix="?",
|
||||
legacy="1.13",
|
||||
)
|
||||
np.format_float_scientific(1, precision=5)
|
||||
np.format_float_positional(1, trim="k")
|
||||
np.array_repr(AR)
|
||||
np.array_str(AR)
|
@ -0,0 +1,27 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
import numpy as np
|
||||
|
||||
AR_i8: np.ndarray[Any, np.dtype[np.int_]] = np.arange(10)
|
||||
ar_iter = np.lib.Arrayterator(AR_i8)
|
||||
|
||||
ar_iter.var
|
||||
ar_iter.buf_size
|
||||
ar_iter.start
|
||||
ar_iter.stop
|
||||
ar_iter.step
|
||||
ar_iter.shape
|
||||
ar_iter.flat
|
||||
|
||||
ar_iter.__array__()
|
||||
|
||||
for i in ar_iter:
|
||||
pass
|
||||
|
||||
ar_iter[0]
|
||||
ar_iter[...]
|
||||
ar_iter[:]
|
||||
ar_iter[0, 0, 0]
|
||||
ar_iter[..., 0, :]
|
@ -0,0 +1,131 @@
|
||||
import numpy as np
|
||||
|
||||
i8 = np.int64(1)
|
||||
u8 = np.uint64(1)
|
||||
|
||||
i4 = np.int32(1)
|
||||
u4 = np.uint32(1)
|
||||
|
||||
b_ = np.bool(1)
|
||||
|
||||
b = bool(1)
|
||||
i = int(1)
|
||||
|
||||
AR = np.array([0, 1, 2], dtype=np.int32)
|
||||
AR.setflags(write=False)
|
||||
|
||||
|
||||
i8 << i8
|
||||
i8 >> i8
|
||||
i8 | i8
|
||||
i8 ^ i8
|
||||
i8 & i8
|
||||
|
||||
i << AR
|
||||
i >> AR
|
||||
i | AR
|
||||
i ^ AR
|
||||
i & AR
|
||||
|
||||
i8 << AR
|
||||
i8 >> AR
|
||||
i8 | AR
|
||||
i8 ^ AR
|
||||
i8 & AR
|
||||
|
||||
i4 << i4
|
||||
i4 >> i4
|
||||
i4 | i4
|
||||
i4 ^ i4
|
||||
i4 & i4
|
||||
|
||||
i8 << i4
|
||||
i8 >> i4
|
||||
i8 | i4
|
||||
i8 ^ i4
|
||||
i8 & i4
|
||||
|
||||
i8 << i
|
||||
i8 >> i
|
||||
i8 | i
|
||||
i8 ^ i
|
||||
i8 & i
|
||||
|
||||
i8 << b_
|
||||
i8 >> b_
|
||||
i8 | b_
|
||||
i8 ^ b_
|
||||
i8 & b_
|
||||
|
||||
i8 << b
|
||||
i8 >> b
|
||||
i8 | b
|
||||
i8 ^ b
|
||||
i8 & b
|
||||
|
||||
u8 << u8
|
||||
u8 >> u8
|
||||
u8 | u8
|
||||
u8 ^ u8
|
||||
u8 & u8
|
||||
|
||||
u4 << u4
|
||||
u4 >> u4
|
||||
u4 | u4
|
||||
u4 ^ u4
|
||||
u4 & u4
|
||||
|
||||
u4 << i4
|
||||
u4 >> i4
|
||||
u4 | i4
|
||||
u4 ^ i4
|
||||
u4 & i4
|
||||
|
||||
u4 << i
|
||||
u4 >> i
|
||||
u4 | i
|
||||
u4 ^ i
|
||||
u4 & i
|
||||
|
||||
u8 << b_
|
||||
u8 >> b_
|
||||
u8 | b_
|
||||
u8 ^ b_
|
||||
u8 & b_
|
||||
|
||||
u8 << b
|
||||
u8 >> b
|
||||
u8 | b
|
||||
u8 ^ b
|
||||
u8 & b
|
||||
|
||||
b_ << b_
|
||||
b_ >> b_
|
||||
b_ | b_
|
||||
b_ ^ b_
|
||||
b_ & b_
|
||||
|
||||
b_ << AR
|
||||
b_ >> AR
|
||||
b_ | AR
|
||||
b_ ^ AR
|
||||
b_ & AR
|
||||
|
||||
b_ << b
|
||||
b_ >> b
|
||||
b_ | b
|
||||
b_ ^ b
|
||||
b_ & b
|
||||
|
||||
b_ << i
|
||||
b_ >> i
|
||||
b_ | i
|
||||
b_ ^ i
|
||||
b_ & i
|
||||
|
||||
~i8
|
||||
~i4
|
||||
~u8
|
||||
~u4
|
||||
~b_
|
||||
~AR
|
@ -0,0 +1,301 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
import numpy as np
|
||||
|
||||
c16 = np.complex128()
|
||||
f8 = np.float64()
|
||||
i8 = np.int64()
|
||||
u8 = np.uint64()
|
||||
|
||||
c8 = np.complex64()
|
||||
f4 = np.float32()
|
||||
i4 = np.int32()
|
||||
u4 = np.uint32()
|
||||
|
||||
dt = np.datetime64(0, "D")
|
||||
td = np.timedelta64(0, "D")
|
||||
|
||||
b_ = np.bool()
|
||||
|
||||
b = bool()
|
||||
c = complex()
|
||||
f = float()
|
||||
i = int()
|
||||
|
||||
SEQ = (0, 1, 2, 3, 4)
|
||||
|
||||
AR_b: np.ndarray[Any, np.dtype[np.bool]] = np.array([True])
|
||||
AR_u: np.ndarray[Any, np.dtype[np.uint32]] = np.array([1], dtype=np.uint32)
|
||||
AR_i: np.ndarray[Any, np.dtype[np.int_]] = np.array([1])
|
||||
AR_f: np.ndarray[Any, np.dtype[np.float64]] = np.array([1.0])
|
||||
AR_c: np.ndarray[Any, np.dtype[np.complex128]] = np.array([1.0j])
|
||||
AR_m: np.ndarray[Any, np.dtype[np.timedelta64]] = np.array([np.timedelta64("1")])
|
||||
AR_M: np.ndarray[Any, np.dtype[np.datetime64]] = np.array([np.datetime64("1")])
|
||||
AR_O: np.ndarray[Any, np.dtype[np.object_]] = np.array([1], dtype=object)
|
||||
|
||||
# Arrays
|
||||
|
||||
AR_b > AR_b
|
||||
AR_b > AR_u
|
||||
AR_b > AR_i
|
||||
AR_b > AR_f
|
||||
AR_b > AR_c
|
||||
|
||||
AR_u > AR_b
|
||||
AR_u > AR_u
|
||||
AR_u > AR_i
|
||||
AR_u > AR_f
|
||||
AR_u > AR_c
|
||||
|
||||
AR_i > AR_b
|
||||
AR_i > AR_u
|
||||
AR_i > AR_i
|
||||
AR_i > AR_f
|
||||
AR_i > AR_c
|
||||
|
||||
AR_f > AR_b
|
||||
AR_f > AR_u
|
||||
AR_f > AR_i
|
||||
AR_f > AR_f
|
||||
AR_f > AR_c
|
||||
|
||||
AR_c > AR_b
|
||||
AR_c > AR_u
|
||||
AR_c > AR_i
|
||||
AR_c > AR_f
|
||||
AR_c > AR_c
|
||||
|
||||
AR_m > AR_b
|
||||
AR_m > AR_u
|
||||
AR_m > AR_i
|
||||
AR_b > AR_m
|
||||
AR_u > AR_m
|
||||
AR_i > AR_m
|
||||
|
||||
AR_M > AR_M
|
||||
|
||||
AR_O > AR_O
|
||||
1 > AR_O
|
||||
AR_O > 1
|
||||
|
||||
# Time structures
|
||||
|
||||
dt > dt
|
||||
|
||||
td > td
|
||||
td > i
|
||||
td > i4
|
||||
td > i8
|
||||
td > AR_i
|
||||
td > SEQ
|
||||
|
||||
# boolean
|
||||
|
||||
b_ > b
|
||||
b_ > b_
|
||||
b_ > i
|
||||
b_ > i8
|
||||
b_ > i4
|
||||
b_ > u8
|
||||
b_ > u4
|
||||
b_ > f
|
||||
b_ > f8
|
||||
b_ > f4
|
||||
b_ > c
|
||||
b_ > c16
|
||||
b_ > c8
|
||||
b_ > AR_i
|
||||
b_ > SEQ
|
||||
|
||||
# Complex
|
||||
|
||||
c16 > c16
|
||||
c16 > f8
|
||||
c16 > i8
|
||||
c16 > c8
|
||||
c16 > f4
|
||||
c16 > i4
|
||||
c16 > b_
|
||||
c16 > b
|
||||
c16 > c
|
||||
c16 > f
|
||||
c16 > i
|
||||
c16 > AR_i
|
||||
c16 > SEQ
|
||||
|
||||
c16 > c16
|
||||
f8 > c16
|
||||
i8 > c16
|
||||
c8 > c16
|
||||
f4 > c16
|
||||
i4 > c16
|
||||
b_ > c16
|
||||
b > c16
|
||||
c > c16
|
||||
f > c16
|
||||
i > c16
|
||||
AR_i > c16
|
||||
SEQ > c16
|
||||
|
||||
c8 > c16
|
||||
c8 > f8
|
||||
c8 > i8
|
||||
c8 > c8
|
||||
c8 > f4
|
||||
c8 > i4
|
||||
c8 > b_
|
||||
c8 > b
|
||||
c8 > c
|
||||
c8 > f
|
||||
c8 > i
|
||||
c8 > AR_i
|
||||
c8 > SEQ
|
||||
|
||||
c16 > c8
|
||||
f8 > c8
|
||||
i8 > c8
|
||||
c8 > c8
|
||||
f4 > c8
|
||||
i4 > c8
|
||||
b_ > c8
|
||||
b > c8
|
||||
c > c8
|
||||
f > c8
|
||||
i > c8
|
||||
AR_i > c8
|
||||
SEQ > c8
|
||||
|
||||
# Float
|
||||
|
||||
f8 > f8
|
||||
f8 > i8
|
||||
f8 > f4
|
||||
f8 > i4
|
||||
f8 > b_
|
||||
f8 > b
|
||||
f8 > c
|
||||
f8 > f
|
||||
f8 > i
|
||||
f8 > AR_i
|
||||
f8 > SEQ
|
||||
|
||||
f8 > f8
|
||||
i8 > f8
|
||||
f4 > f8
|
||||
i4 > f8
|
||||
b_ > f8
|
||||
b > f8
|
||||
c > f8
|
||||
f > f8
|
||||
i > f8
|
||||
AR_i > f8
|
||||
SEQ > f8
|
||||
|
||||
f4 > f8
|
||||
f4 > i8
|
||||
f4 > f4
|
||||
f4 > i4
|
||||
f4 > b_
|
||||
f4 > b
|
||||
f4 > c
|
||||
f4 > f
|
||||
f4 > i
|
||||
f4 > AR_i
|
||||
f4 > SEQ
|
||||
|
||||
f8 > f4
|
||||
i8 > f4
|
||||
f4 > f4
|
||||
i4 > f4
|
||||
b_ > f4
|
||||
b > f4
|
||||
c > f4
|
||||
f > f4
|
||||
i > f4
|
||||
AR_i > f4
|
||||
SEQ > f4
|
||||
|
||||
# Int
|
||||
|
||||
i8 > i8
|
||||
i8 > u8
|
||||
i8 > i4
|
||||
i8 > u4
|
||||
i8 > b_
|
||||
i8 > b
|
||||
i8 > c
|
||||
i8 > f
|
||||
i8 > i
|
||||
i8 > AR_i
|
||||
i8 > SEQ
|
||||
|
||||
u8 > u8
|
||||
u8 > i4
|
||||
u8 > u4
|
||||
u8 > b_
|
||||
u8 > b
|
||||
u8 > c
|
||||
u8 > f
|
||||
u8 > i
|
||||
u8 > AR_i
|
||||
u8 > SEQ
|
||||
|
||||
i8 > i8
|
||||
u8 > i8
|
||||
i4 > i8
|
||||
u4 > i8
|
||||
b_ > i8
|
||||
b > i8
|
||||
c > i8
|
||||
f > i8
|
||||
i > i8
|
||||
AR_i > i8
|
||||
SEQ > i8
|
||||
|
||||
u8 > u8
|
||||
i4 > u8
|
||||
u4 > u8
|
||||
b_ > u8
|
||||
b > u8
|
||||
c > u8
|
||||
f > u8
|
||||
i > u8
|
||||
AR_i > u8
|
||||
SEQ > u8
|
||||
|
||||
i4 > i8
|
||||
i4 > i4
|
||||
i4 > i
|
||||
i4 > b_
|
||||
i4 > b
|
||||
i4 > AR_i
|
||||
i4 > SEQ
|
||||
|
||||
u4 > i8
|
||||
u4 > i4
|
||||
u4 > u8
|
||||
u4 > u4
|
||||
u4 > i
|
||||
u4 > b_
|
||||
u4 > b
|
||||
u4 > AR_i
|
||||
u4 > SEQ
|
||||
|
||||
i8 > i4
|
||||
i4 > i4
|
||||
i > i4
|
||||
b_ > i4
|
||||
b > i4
|
||||
AR_i > i4
|
||||
SEQ > i4
|
||||
|
||||
i8 > u4
|
||||
i4 > u4
|
||||
u8 > u4
|
||||
u4 > u4
|
||||
b_ > u4
|
||||
b > u4
|
||||
i > u4
|
||||
AR_i > u4
|
||||
SEQ > u4
|
@ -0,0 +1,57 @@
|
||||
import numpy as np
|
||||
|
||||
dtype_obj = np.dtype(np.str_)
|
||||
void_dtype_obj = np.dtype([("f0", np.float64), ("f1", np.float32)])
|
||||
|
||||
np.dtype(dtype=np.int64)
|
||||
np.dtype(int)
|
||||
np.dtype("int")
|
||||
np.dtype(None)
|
||||
|
||||
np.dtype((int, 2))
|
||||
np.dtype((int, (1,)))
|
||||
|
||||
np.dtype({"names": ["a", "b"], "formats": [int, float]})
|
||||
np.dtype({"names": ["a"], "formats": [int], "titles": [object]})
|
||||
np.dtype({"names": ["a"], "formats": [int], "titles": [object()]})
|
||||
|
||||
np.dtype([("name", np.str_, 16), ("grades", np.float64, (2,)), ("age", "int32")])
|
||||
|
||||
np.dtype(
|
||||
{
|
||||
"names": ["a", "b"],
|
||||
"formats": [int, float],
|
||||
"itemsize": 9,
|
||||
"aligned": False,
|
||||
"titles": ["x", "y"],
|
||||
"offsets": [0, 1],
|
||||
}
|
||||
)
|
||||
|
||||
np.dtype((np.float64, float))
|
||||
|
||||
|
||||
class Test:
|
||||
dtype = np.dtype(float)
|
||||
|
||||
|
||||
np.dtype(Test())
|
||||
|
||||
# Methods and attributes
|
||||
dtype_obj.base
|
||||
dtype_obj.subdtype
|
||||
dtype_obj.newbyteorder()
|
||||
dtype_obj.type
|
||||
dtype_obj.name
|
||||
dtype_obj.names
|
||||
|
||||
dtype_obj * 0
|
||||
dtype_obj * 2
|
||||
|
||||
0 * dtype_obj
|
||||
2 * dtype_obj
|
||||
|
||||
void_dtype_obj["f0"]
|
||||
void_dtype_obj[0]
|
||||
void_dtype_obj[["f0", "f1"]]
|
||||
void_dtype_obj[["f0"]]
|
@ -0,0 +1,36 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import numpy as np
|
||||
|
||||
AR_LIKE_b = [True, True, True]
|
||||
AR_LIKE_u = [np.uint32(1), np.uint32(2), np.uint32(3)]
|
||||
AR_LIKE_i = [1, 2, 3]
|
||||
AR_LIKE_f = [1.0, 2.0, 3.0]
|
||||
AR_LIKE_c = [1j, 2j, 3j]
|
||||
AR_LIKE_U = ["1", "2", "3"]
|
||||
|
||||
OUT_f: np.ndarray[Any, np.dtype[np.float64]] = np.empty(3, dtype=np.float64)
|
||||
OUT_c: np.ndarray[Any, np.dtype[np.complex128]] = np.empty(3, dtype=np.complex128)
|
||||
|
||||
np.einsum("i,i->i", AR_LIKE_b, AR_LIKE_b)
|
||||
np.einsum("i,i->i", AR_LIKE_u, AR_LIKE_u)
|
||||
np.einsum("i,i->i", AR_LIKE_i, AR_LIKE_i)
|
||||
np.einsum("i,i->i", AR_LIKE_f, AR_LIKE_f)
|
||||
np.einsum("i,i->i", AR_LIKE_c, AR_LIKE_c)
|
||||
np.einsum("i,i->i", AR_LIKE_b, AR_LIKE_i)
|
||||
np.einsum("i,i,i,i->i", AR_LIKE_b, AR_LIKE_u, AR_LIKE_i, AR_LIKE_c)
|
||||
|
||||
np.einsum("i,i->i", AR_LIKE_f, AR_LIKE_f, dtype="c16")
|
||||
np.einsum("i,i->i", AR_LIKE_U, AR_LIKE_U, dtype=bool, casting="unsafe")
|
||||
np.einsum("i,i->i", AR_LIKE_f, AR_LIKE_f, out=OUT_c)
|
||||
np.einsum("i,i->i", AR_LIKE_U, AR_LIKE_U, dtype=int, casting="unsafe", out=OUT_f)
|
||||
|
||||
np.einsum_path("i,i->i", AR_LIKE_b, AR_LIKE_b)
|
||||
np.einsum_path("i,i->i", AR_LIKE_u, AR_LIKE_u)
|
||||
np.einsum_path("i,i->i", AR_LIKE_i, AR_LIKE_i)
|
||||
np.einsum_path("i,i->i", AR_LIKE_f, AR_LIKE_f)
|
||||
np.einsum_path("i,i->i", AR_LIKE_c, AR_LIKE_c)
|
||||
np.einsum_path("i,i->i", AR_LIKE_b, AR_LIKE_i)
|
||||
np.einsum_path("i,i,i,i->i", AR_LIKE_b, AR_LIKE_u, AR_LIKE_i, AR_LIKE_c)
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user