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

1""" 

2DType classes and utility (:mod:`numpy.dtypes`) 

3=============================================== 

4 

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`. 

8 

9Similar to the builtin ``types`` module, this submodule defines types (classes) 

10that are not widely used directly. 

11 

12.. versionadded:: NumPy 1.25 

13 

14 The dtypes module is new in NumPy 1.25. Previously DType classes were 

15 only accessible indirectly. 

16 

17 

18DType classes 

19------------- 

20 

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. 

26 

27.. list-table:: 

28 :header-rows: 1 

29 

30 * - Group 

31 - DType class 

32 

33 * - Boolean 

34 - ``BoolDType`` 

35 

36 * - Bit-sized integers 

37 - ``Int8DType``, ``UInt8DType``, ``Int16DType``, ``UInt16DType``, 

38 ``Int32DType``, ``UInt32DType``, ``Int64DType``, ``UInt64DType`` 

39 

40 * - C-named integers (may be aliases) 

41 - ``ByteDType``, ``UByteDType``, ``ShortDType``, ``UShortDType``, 

42 ``IntDType``, ``UIntDType``, ``LongDType``, ``ULongDType``, 

43 ``LongLongDType``, ``ULongLongDType`` 

44 

45 * - Floating point 

46 - ``Float16DType``, ``Float32DType``, ``Float64DType``, 

47 ``LongDoubleDType`` 

48 

49 * - Complex 

50 - ``Complex64DType``, ``Complex128DType``, ``CLongDoubleDType`` 

51 

52 * - Strings 

53 - ``BytesDType``, ``BytesDType`` 

54 

55 * - Times 

56 - ``DateTime64DType``, ``TimeDelta64DType`` 

57 

58 * - Others 

59 - ``ObjectDType``, ``VoidDType`` 

60 

61""" 

62 

63__all__ = [] 

64 

65 

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 

70 

71 setattr(dtypes, DType.__name__, DType) 

72 __all__.append(DType.__name__) 

73 

74 if alias: 

75 alias = alias.removeprefix("numpy.dtypes.") 

76 setattr(dtypes, alias, DType) 

77 __all__.append(alias)