__init__.py 3.2 KB

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