summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@gmail.com>2023-02-28 19:38:45 +0000
committerRalf Gommers <ralf.gommers@gmail.com>2023-02-28 23:15:40 +0000
commit768bbec24fff74cb59a173accf7fbeda6aca89a1 (patch)
tree041b801d111834c5e16b543d82482af5305f6d19
parent486878b37fc7439a3b2b87747f50db9b62fea8eb (diff)
downloadnumpy-768bbec24fff74cb59a173accf7fbeda6aca89a1.tar.gz
DEP: deprecate `np.round_`
Closes gh-22617
-rw-r--r--doc/release/upcoming_changes/23302.deprecation.rst1
-rw-r--r--numpy/core/__init__.py2
-rw-r--r--numpy/core/fromnumeric.py12
-rw-r--r--numpy/core/tests/test_deprecations.py6
-rw-r--r--numpy/ma/tests/test_extras.py4
5 files changed, 21 insertions, 4 deletions
diff --git a/doc/release/upcoming_changes/23302.deprecation.rst b/doc/release/upcoming_changes/23302.deprecation.rst
new file mode 100644
index 000000000..9e36d658c
--- /dev/null
+++ b/doc/release/upcoming_changes/23302.deprecation.rst
@@ -0,0 +1 @@
+* ``np.round_`` is deprecated. Use `np.round` instead.
diff --git a/numpy/core/__init__.py b/numpy/core/__init__.py
index 1079c41df..f70743cbe 100644
--- a/numpy/core/__init__.py
+++ b/numpy/core/__init__.py
@@ -92,7 +92,7 @@ from . import einsumfunc
from .einsumfunc import *
del nt
-from .fromnumeric import amax as max, amin as min, round_ as round
+from .fromnumeric import amax as max, amin as min
from .numeric import absolute as abs
# do this after everything else, to minimize the chance of this misleadingly
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py
index 7d3336f88..96f585066 100644
--- a/numpy/core/fromnumeric.py
+++ b/numpy/core/fromnumeric.py
@@ -21,7 +21,7 @@ __all__ = [
'argmin', 'argpartition', 'argsort', 'around', 'choose', 'clip',
'compress', 'cumprod', 'cumproduct', 'cumsum', 'diagonal', 'mean',
'ndim', 'nonzero', 'partition', 'prod', 'product', 'ptp', 'put',
- 'ravel', 'repeat', 'reshape', 'resize', 'round_',
+ 'ravel', 'repeat', 'reshape', 'resize', 'round', 'round_',
'searchsorted', 'shape', 'size', 'sometrue', 'sort', 'squeeze',
'std', 'sum', 'swapaxes', 'take', 'trace', 'transpose', 'var',
]
@@ -3337,6 +3337,9 @@ def around(a, decimals=0, out=None):
return _wrapfunc(a, 'round', decimals=decimals, out=out)
+round = around
+
+
def _mean_dispatcher(a, axis=None, dtype=None, out=None, keepdims=None, *,
where=None):
return (a, where, out)
@@ -3760,10 +3763,17 @@ def round_(a, decimals=0, out=None):
`~numpy.round_` is a disrecommended backwards-compatibility
alias of `~numpy.around` and `~numpy.round`.
+ .. deprecated:: 1.25.0
+ ``round_`` is deprecated as of NumPy 1.25.0, and will be
+ removed in NumPy 2.0. Please use `round` instead.
+
See Also
--------
around : equivalent function; see for details.
"""
+ warnings.warn("`round_` is deprecated as of NumPy 1.25.0, and will be "
+ "removed in NumPy 2.0. Please use `round` instead.",
+ DeprecationWarning, stacklevel=2)
return around(a, decimals=decimals, out=out)
diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py
index ac4761b50..8ff52c885 100644
--- a/numpy/core/tests/test_deprecations.py
+++ b/numpy/core/tests/test_deprecations.py
@@ -901,3 +901,9 @@ class TestDeprecatedFinfo(_DeprecationTestCase):
# Deprecated in NumPy 1.25, 2023-01-16
def test_deprecated_none(self):
self.assert_deprecated(np.finfo, args=(None,))
+
+
+class TestRound_(_DeprecationTestCase):
+ # 2023-02-28, 1.25.0
+ def test_round_(self):
+ self.assert_deprecated(lambda: np.round_(np.array([1.5, 2.5, 3.5])))
diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py
index 38603fb84..e59ba3656 100644
--- a/numpy/ma/tests/test_extras.py
+++ b/numpy/ma/tests/test_extras.py
@@ -387,8 +387,8 @@ class TestConcatenator:
# Tests mr_ on 2D arrays.
a_1 = np.random.rand(5, 5)
a_2 = np.random.rand(5, 5)
- m_1 = np.round_(np.random.rand(5, 5), 0)
- m_2 = np.round_(np.random.rand(5, 5), 0)
+ m_1 = np.round(np.random.rand(5, 5), 0)
+ m_2 = np.round(np.random.rand(5, 5), 0)
b_1 = masked_array(a_1, mask=m_1)
b_2 = masked_array(a_2, mask=m_2)
# append columns