diff options
| -rw-r--r-- | numpy/core/numerictypes.py | 9 | ||||
| -rw-r--r-- | numpy/core/numerictypes.pyi | 65 |
2 files changed, 71 insertions, 3 deletions
diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index 467e2ed23..12f424fd4 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -511,8 +511,15 @@ cast = _typedict() for key in _concrete_types: cast[key] = lambda x, k=key: array(x, copy=False).astype(k) + +def _scalar_type_key(typ): + """A ``key`` function for `sorted`.""" + dt = dtype(typ) + return (dt.kind.lower(), dt.itemsize) + + ScalarType = [int, float, complex, int, bool, bytes, str, memoryview] -ScalarType.extend(_concrete_types) +ScalarType += sorted(_concrete_types, key=_scalar_type_key) ScalarType = tuple(ScalarType) diff --git a/numpy/core/numerictypes.pyi b/numpy/core/numerictypes.pyi index cf2cc1e8d..fd4aa3fda 100644 --- a/numpy/core/numerictypes.pyi +++ b/numpy/core/numerictypes.pyi @@ -13,7 +13,35 @@ from typing import ( List, ) -from numpy import generic, ndarray, dtype +from numpy import ( + ndarray, + dtype, + generic, + bool_, + ubyte, + ushort, + uintc, + uint, + ulonglong, + byte, + short, + intc, + int_, + longlong, + half, + single, + double, + longdouble, + csingle, + cdouble, + clongdouble, + datetime64, + timedelta64, + object_, + str_, + bytes_, + void, +) from numpy.core._type_aliases import ( sctypeDict as sctypeDict, @@ -76,4 +104,37 @@ def find_common_type( cast: _typedict[_CastFunc] nbytes: _typedict[int] typecodes: _TypeCodes -ScalarType: Tuple[type, ...] +ScalarType: Tuple[ + Type[int], + Type[float], + Type[complex], + Type[int], + Type[bool], + Type[bytes], + Type[str], + Type[memoryview], + Type[bool_], + Type[csingle], + Type[cdouble], + Type[clongdouble], + Type[half], + Type[single], + Type[double], + Type[longdouble], + Type[byte], + Type[short], + Type[intc], + Type[int_], + Type[longlong], + Type[timedelta64], + Type[datetime64], + Type[object_], + Type[bytes_], + Type[str_], + Type[ubyte], + Type[ushort], + Type[uintc], + Type[uint], + Type[ulonglong], + Type[void], +] |
