__init__.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. """
  2. ``numpy.lib`` is mostly a space for implementing functions that don't
  3. belong in core or in another NumPy submodule with a clear purpose
  4. (e.g. ``random``, ``fft``, ``linalg``, ``ma``).
  5. ``numpy.lib``'s private submodules contain basic functions that are used by
  6. other public modules and are useful to have in the main name-space.
  7. """
  8. # Public submodules
  9. # Note: recfunctions is public, but not imported
  10. from numpy._core._multiarray_umath import add_docstring, tracemalloc_domain
  11. from numpy._core.function_base import add_newdoc
  12. # Private submodules
  13. # load module names. See https://github.com/networkx/networkx/issues/5838
  14. from . import (
  15. _arraypad_impl,
  16. _arraysetops_impl,
  17. _arrayterator_impl,
  18. _function_base_impl,
  19. _histograms_impl,
  20. _index_tricks_impl,
  21. _nanfunctions_impl,
  22. _npyio_impl,
  23. _polynomial_impl,
  24. _shape_base_impl,
  25. _stride_tricks_impl,
  26. _twodim_base_impl,
  27. _type_check_impl,
  28. _ufunclike_impl,
  29. _utils_impl,
  30. _version,
  31. array_utils,
  32. format,
  33. introspect,
  34. mixins,
  35. npyio,
  36. scimath,
  37. stride_tricks,
  38. )
  39. # numpy.lib namespace members
  40. from ._arrayterator_impl import Arrayterator
  41. from ._version import NumpyVersion
  42. __all__ = [
  43. "Arrayterator", "add_docstring", "add_newdoc", "array_utils",
  44. "format", "introspect", "mixins", "NumpyVersion", "npyio", "scimath",
  45. "stride_tricks", "tracemalloc_domain",
  46. ]
  47. add_newdoc.__module__ = "numpy.lib"
  48. from numpy._pytesttester import PytestTester
  49. test = PytestTester(__name__)
  50. del PytestTester
  51. def __getattr__(attr):
  52. # Warn for deprecated/removed aliases
  53. import math
  54. import warnings
  55. if attr == "math":
  56. warnings.warn(
  57. "`np.lib.math` is a deprecated alias for the standard library "
  58. "`math` module (Deprecated Numpy 1.25). Replace usages of "
  59. "`numpy.lib.math` with `math`", DeprecationWarning, stacklevel=2)
  60. return math
  61. elif attr == "emath":
  62. raise AttributeError(
  63. "numpy.lib.emath was an alias for emath module that was removed "
  64. "in NumPy 2.0. Replace usages of numpy.lib.emath with "
  65. "numpy.emath.",
  66. name=None
  67. )
  68. elif attr in (
  69. "histograms", "type_check", "nanfunctions", "function_base",
  70. "arraypad", "arraysetops", "ufunclike", "utils", "twodim_base",
  71. "shape_base", "polynomial", "index_tricks",
  72. ):
  73. raise AttributeError(
  74. f"numpy.lib.{attr} is now private. If you are using a public "
  75. "function, it should be available in the main numpy namespace, "
  76. "otherwise check the NumPy 2.0 migration guide.",
  77. name=None
  78. )
  79. elif attr == "arrayterator":
  80. raise AttributeError(
  81. "numpy.lib.arrayterator submodule is now private. To access "
  82. "Arrayterator class use numpy.lib.Arrayterator.",
  83. name=None
  84. )
  85. else:
  86. raise AttributeError(f"module {__name__!r} has no attribute {attr!r}")