Coverage for /usr/lib/python3/dist-packages/numpy/dtypes.py: 100%
9 statements
« prev ^ index » next coverage.py v7.4.4, created at 2025-06-14 15:25 +0200
« prev ^ index » next coverage.py v7.4.4, created at 2025-06-14 15:25 +0200
1"""
2DType classes and utility (:mod:`numpy.dtypes`)
3===============================================
5This module is home to specific dtypes related functionality and their classes.
6For more general information about dtypes, also see `numpy.dtype` and
7:ref:`arrays.dtypes`.
9Similar to the builtin ``types`` module, this submodule defines types (classes)
10that are not widely used directly.
12.. versionadded:: NumPy 1.25
14 The dtypes module is new in NumPy 1.25. Previously DType classes were
15 only accessible indirectly.
18DType classes
19-------------
21The following are the classes of the corresponding NumPy dtype instances and
22NumPy scalar types. The classes can be used in ``isinstance`` checks and can
23also be instantiated or used directly. Direct use of these classes is not
24typical, since their scalar counterparts (e.g. ``np.float64``) or strings
25like ``"float64"`` can be used.
27.. list-table::
28 :header-rows: 1
30 * - Group
31 - DType class
33 * - Boolean
34 - ``BoolDType``
36 * - Bit-sized integers
37 - ``Int8DType``, ``UInt8DType``, ``Int16DType``, ``UInt16DType``,
38 ``Int32DType``, ``UInt32DType``, ``Int64DType``, ``UInt64DType``
40 * - C-named integers (may be aliases)
41 - ``ByteDType``, ``UByteDType``, ``ShortDType``, ``UShortDType``,
42 ``IntDType``, ``UIntDType``, ``LongDType``, ``ULongDType``,
43 ``LongLongDType``, ``ULongLongDType``
45 * - Floating point
46 - ``Float16DType``, ``Float32DType``, ``Float64DType``,
47 ``LongDoubleDType``
49 * - Complex
50 - ``Complex64DType``, ``Complex128DType``, ``CLongDoubleDType``
52 * - Strings
53 - ``BytesDType``, ``BytesDType``
55 * - Times
56 - ``DateTime64DType``, ``TimeDelta64DType``
58 * - Others
59 - ``ObjectDType``, ``VoidDType``
61"""
63__all__ = []
66def _add_dtype_helper(DType, alias):
67 # Function to add DTypes a bit more conveniently without channeling them
68 # through `numpy.core._multiarray_umath` namespace or similar.
69 from numpy import dtypes
71 setattr(dtypes, DType.__name__, DType)
72 __all__.append(DType.__name__)
74 if alias:
75 alias = alias.removeprefix("numpy.dtypes.")
76 setattr(dtypes, alias, DType)
77 __all__.append(alias)