dtypes.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """
  2. This module is home to specific dtypes related functionality and their classes.
  3. For more general information about dtypes, also see `numpy.dtype` and
  4. :ref:`arrays.dtypes`.
  5. Similar to the builtin ``types`` module, this submodule defines types (classes)
  6. that are not widely used directly.
  7. .. versionadded:: NumPy 1.25
  8. The dtypes module is new in NumPy 1.25. Previously DType classes were
  9. only accessible indirectly.
  10. DType classes
  11. -------------
  12. The following are the classes of the corresponding NumPy dtype instances and
  13. NumPy scalar types. The classes can be used in ``isinstance`` checks and can
  14. also be instantiated or used directly. Direct use of these classes is not
  15. typical, since their scalar counterparts (e.g. ``np.float64``) or strings
  16. like ``"float64"`` can be used.
  17. """
  18. # See doc/source/reference/routines.dtypes.rst for module-level docs
  19. __all__ = []
  20. def _add_dtype_helper(DType, alias):
  21. # Function to add DTypes a bit more conveniently without channeling them
  22. # through `numpy._core._multiarray_umath` namespace or similar.
  23. from numpy import dtypes
  24. setattr(dtypes, DType.__name__, DType)
  25. __all__.append(DType.__name__)
  26. if alias:
  27. alias = alias.removeprefix("numpy.dtypes.")
  28. setattr(dtypes, alias, DType)
  29. __all__.append(alias)