diff options
| -rw-r--r-- | numpy/__init__.py | 10 | ||||
| -rw-r--r-- | numpy/core/tests/test_deprecations.py | 9 | ||||
| -rw-r--r-- | numpy/lib/__init__.py | 19 |
3 files changed, 35 insertions, 3 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py index 1880ceace..83b42092f 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -215,7 +215,14 @@ else: __deprecated_attrs__.update({ n: (alias, _msg.format(n=n, an=an)) for n, alias, an in _type_info}) - del _msg, _type_info + import math + + __deprecated_attrs__['math'] = (math, + "`np.math` is a deprecated alias for the standard library `math` " + "module (Deprecated Numpy 1.25). Replace usages of `np.math` with " + "`math`") + + del math, _msg, _type_info from .core import abs # now that numpy modules are imported, can initialize limits @@ -272,6 +279,7 @@ else: # Warn for expired attributes, and return a dummy function # that always raises an exception. import warnings + import math try: msg = __expired_functions__[attr] except KeyError: diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py index 96ae4b2a8..b92a20a12 100644 --- a/numpy/core/tests/test_deprecations.py +++ b/numpy/core/tests/test_deprecations.py @@ -922,3 +922,12 @@ class TestFromnumeric(_DeprecationTestCase): # 2023-03-02, 1.25.0 def test_alltrue(self): self.assert_deprecated(lambda: np.alltrue(np.array([True, False]))) + + +class TestMathAlias(_DeprecationTestCase): + # Deprecated in Numpy 1.25, 2023-04-06 + def test_deprecated_np_math(self): + self.assert_deprecated(lambda: np.math) + + def test_deprecated_np_lib_math(self): + self.assert_deprecated(lambda: np.lib.math) diff --git a/numpy/lib/__init__.py b/numpy/lib/__init__.py index 58166d4b1..d3cc9fee4 100644 --- a/numpy/lib/__init__.py +++ b/numpy/lib/__init__.py @@ -11,7 +11,6 @@ Most contains basic functions that are used by several submodules and are useful to have in the main name-space. """ -import math from numpy.version import version as __version__ @@ -58,7 +57,7 @@ from .arraypad import * from ._version import * from numpy.core._multiarray_umath import tracemalloc_domain -__all__ = ['emath', 'math', 'tracemalloc_domain', 'Arrayterator'] +__all__ = ['emath', 'tracemalloc_domain', 'Arrayterator'] __all__ += type_check.__all__ __all__ += index_tricks.__all__ __all__ += function_base.__all__ @@ -77,3 +76,19 @@ __all__ += histograms.__all__ from numpy._pytesttester import PytestTester test = PytestTester(__name__) del PytestTester + +def __getattr__(attr): + # Warn for reprecated attributes + import math + import warnings + + if attr == 'math': + warnings.warn( + "`np.lib.math` is a deprecated alias for the standard library " + "`math` module (Deprecated Numpy 1.25). Replace usages of " + "`numpy.lib.math` with `math`", DeprecationWarning, stacklevel=2) + return math + else: + raise AttributeError("module {!r} has no attribute " + "{!r}".format(__name__, attr)) + |
