summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2023-03-02 18:17:19 -0500
committerGitHub <noreply@github.com>2023-03-02 18:17:19 -0500
commite57ee3fa15234827bebc2500ea89d5d05e895d2f (patch)
treedaf844e97803f7bfac633c28750612b918df22da /numpy/core
parent6736bd9ad4db2b09b055820af7799a9f3d704394 (diff)
parent3dcc33aa585339f36639f78da70bb35f26609bef (diff)
downloadnumpy-e57ee3fa15234827bebc2500ea89d5d05e895d2f.tar.gz
Merge pull request #23314 from rgommers/depr-product-and-co
DEP: deprecate `product`, `cumproduct`, `sometrue`, `alltrue`
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/fromnumeric.py33
-rw-r--r--numpy/core/tests/test_deprecations.py19
-rw-r--r--numpy/core/tests/test_indexing.py2
-rw-r--r--numpy/core/tests/test_mem_overlap.py2
-rw-r--r--numpy/core/tests/test_memmap.py4
-rw-r--r--numpy/core/tests/test_numeric.py8
-rw-r--r--numpy/core/tests/test_regression.py23
7 files changed, 67 insertions, 24 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py
index ed8b68ecd..7ea2313d1 100644
--- a/numpy/core/fromnumeric.py
+++ b/numpy/core/fromnumeric.py
@@ -3821,6 +3821,7 @@ def round_(a, decimals=0, out=None):
--------
around : equivalent function; see for details.
"""
+ # 2023-02-28, 1.25.0
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)
@@ -3832,10 +3833,18 @@ def product(*args, **kwargs):
"""
Return the product of array elements over a given axis.
+ .. deprecated:: 1.25.0
+ ``product`` is deprecated as of NumPy 1.25.0, and will be
+ removed in NumPy 2.0. Please use `prod` instead.
+
See Also
--------
prod : equivalent function; see for details.
"""
+ # 2023-03-02, 1.25.0
+ warnings.warn("`product` is deprecated as of NumPy 1.25.0, and will be "
+ "removed in NumPy 2.0. Please use `prod` instead.",
+ DeprecationWarning, stacklevel=2)
return prod(*args, **kwargs)
@@ -3844,10 +3853,18 @@ def cumproduct(*args, **kwargs):
"""
Return the cumulative product over the given axis.
+ .. deprecated:: 1.25.0
+ ``cumproduct`` is deprecated as of NumPy 1.25.0, and will be
+ removed in NumPy 2.0. Please use `cumprod` instead.
+
See Also
--------
cumprod : equivalent function; see for details.
"""
+ # 2023-03-02, 1.25.0
+ warnings.warn("`cumproduct` is deprecated as of NumPy 1.25.0, and will be "
+ "removed in NumPy 2.0. Please use `cumprod` instead.",
+ DeprecationWarning, stacklevel=2)
return cumprod(*args, **kwargs)
@@ -3858,10 +3875,18 @@ def sometrue(*args, **kwargs):
Refer to `any` for full documentation.
+ .. deprecated:: 1.25.0
+ ``sometrue`` is deprecated as of NumPy 1.25.0, and will be
+ removed in NumPy 2.0. Please use `any` instead.
+
See Also
--------
any : equivalent function; see for details.
"""
+ # 2023-03-02, 1.25.0
+ warnings.warn("`sometrue` is deprecated as of NumPy 1.25.0, and will be "
+ "removed in NumPy 2.0. Please use `any` instead.",
+ DeprecationWarning, stacklevel=2)
return any(*args, **kwargs)
@@ -3870,8 +3895,16 @@ def alltrue(*args, **kwargs):
"""
Check if all elements of input array are true.
+ .. deprecated:: 1.25.0
+ ``alltrue`` is deprecated as of NumPy 1.25.0, and will be
+ removed in NumPy 2.0. Please use `all` instead.
+
See Also
--------
numpy.all : Equivalent function; see for details.
"""
+ # 2023-03-02, 1.25.0
+ warnings.warn("`alltrue` is deprecated as of NumPy 1.25.0, and will be "
+ "removed in NumPy 2.0. Please use `all` instead.",
+ DeprecationWarning, stacklevel=2)
return all(*args, **kwargs)
diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py
index 8ff52c885..96ae4b2a8 100644
--- a/numpy/core/tests/test_deprecations.py
+++ b/numpy/core/tests/test_deprecations.py
@@ -902,8 +902,23 @@ class TestDeprecatedFinfo(_DeprecationTestCase):
def test_deprecated_none(self):
self.assert_deprecated(np.finfo, args=(None,))
-
-class TestRound_(_DeprecationTestCase):
+class TestFromnumeric(_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])))
+
+ # 2023-03-02, 1.25.0
+ def test_cumproduct(self):
+ self.assert_deprecated(lambda: np.cumproduct(np.array([1, 2, 3])))
+
+ # 2023-03-02, 1.25.0
+ def test_product(self):
+ self.assert_deprecated(lambda: np.product(np.array([1, 2, 3])))
+
+ # 2023-03-02, 1.25.0
+ def test_sometrue(self):
+ self.assert_deprecated(lambda: np.sometrue(np.array([True, False])))
+
+ # 2023-03-02, 1.25.0
+ def test_alltrue(self):
+ self.assert_deprecated(lambda: np.alltrue(np.array([True, False])))
diff --git a/numpy/core/tests/test_indexing.py b/numpy/core/tests/test_indexing.py
index 74075639c..042936702 100644
--- a/numpy/core/tests/test_indexing.py
+++ b/numpy/core/tests/test_indexing.py
@@ -1062,7 +1062,7 @@ class TestMultiIndexingAutomated:
if np.any(_indx >= _size) or np.any(_indx < -_size):
raise IndexError
if len(indx[1:]) == len(orig_slice):
- if np.product(orig_slice) == 0:
+ if np.prod(orig_slice) == 0:
# Work around for a crash or IndexError with 'wrap'
# in some 0-sized cases.
try:
diff --git a/numpy/core/tests/test_mem_overlap.py b/numpy/core/tests/test_mem_overlap.py
index d66decfda..1fd4c4d41 100644
--- a/numpy/core/tests/test_mem_overlap.py
+++ b/numpy/core/tests/test_mem_overlap.py
@@ -55,7 +55,7 @@ def _indices(ndims):
def _check_assignment(srcidx, dstidx):
"""Check assignment arr[dstidx] = arr[srcidx] works."""
- arr = np.arange(np.product(shape)).reshape(shape)
+ arr = np.arange(np.prod(shape)).reshape(shape)
cpy = arr.copy()
diff --git a/numpy/core/tests/test_memmap.py b/numpy/core/tests/test_memmap.py
index 914f86f14..ad074b312 100644
--- a/numpy/core/tests/test_memmap.py
+++ b/numpy/core/tests/test_memmap.py
@@ -6,7 +6,7 @@ from pathlib import Path
from tempfile import NamedTemporaryFile, TemporaryFile
from numpy import (
- memmap, sum, average, product, ndarray, isscalar, add, subtract, multiply)
+ memmap, sum, average, prod, ndarray, isscalar, add, subtract, multiply)
from numpy import arange, allclose, asarray
from numpy.testing import (
@@ -153,7 +153,7 @@ class TestMemmap:
with suppress_warnings() as sup:
sup.filter(FutureWarning, "np.average currently does not preserve")
- for unary_op in [sum, average, product]:
+ for unary_op in [sum, average, prod]:
result = unary_op(fp)
assert_(isscalar(result))
assert_(result.__class__ is self.data[0, 0].__class__)
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py
index 3cc168b34..f81f563cd 100644
--- a/numpy/core/tests/test_numeric.py
+++ b/numpy/core/tests/test_numeric.py
@@ -114,7 +114,9 @@ class TestNonarrayArgs:
def test_cumproduct(self):
A = [[1, 2, 3], [4, 5, 6]]
- assert_(np.all(np.cumproduct(A) == np.array([1, 2, 6, 24, 120, 720])))
+ with assert_warns(DeprecationWarning):
+ expected = np.array([1, 2, 6, 24, 120, 720])
+ assert_(np.all(np.cumproduct(A) == expected))
def test_diagonal(self):
a = [[0, 1, 2, 3],
@@ -1193,8 +1195,8 @@ class TestFromiter:
expected = np.array(list(self.makegen()))
a = np.fromiter(self.makegen(), int)
a20 = np.fromiter(self.makegen(), int, 20)
- assert_(np.alltrue(a == expected, axis=0))
- assert_(np.alltrue(a20 == expected[:20], axis=0))
+ assert_(np.all(a == expected, axis=0))
+ assert_(np.all(a20 == expected[:20], axis=0))
def load_data(self, n, eindex):
# Utility method for the issue 2592 tests.
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index 413ece045..fdd536bb9 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -516,22 +516,15 @@ class TestRegression:
def test_method_args(self):
# Make sure methods and functions have same default axis
# keyword and arguments
- funcs1 = ['argmax', 'argmin', 'sum', ('product', 'prod'),
- ('sometrue', 'any'),
- ('alltrue', 'all'), 'cumsum', ('cumproduct', 'cumprod'),
- 'ptp', 'cumprod', 'prod', 'std', 'var', 'mean',
- 'round', 'min', 'max', 'argsort', 'sort']
+ funcs1 = ['argmax', 'argmin', 'sum', 'any', 'all', 'cumsum',
+ 'ptp', 'cumprod', 'prod', 'std', 'var', 'mean',
+ 'round', 'min', 'max', 'argsort', 'sort']
funcs2 = ['compress', 'take', 'repeat']
for func in funcs1:
arr = np.random.rand(8, 7)
arr2 = arr.copy()
- if isinstance(func, tuple):
- func_meth = func[1]
- func = func[0]
- else:
- func_meth = func
- res1 = getattr(arr, func_meth)()
+ res1 = getattr(arr, func)()
res2 = getattr(np, func)(arr2)
if res1 is None:
res1 = arr
@@ -1336,8 +1329,8 @@ class TestRegression:
# Ticket #1058
a = np.fromiter(list(range(10)), dtype='b')
b = np.fromiter(list(range(10)), dtype='B')
- assert_(np.alltrue(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
- assert_(np.alltrue(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
+ assert_(np.all(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
+ assert_(np.all(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
def test_array_from_sequence_scalar_array(self):
# Ticket #1078: segfaults when creating an array with a sequence of
@@ -1515,8 +1508,8 @@ class TestRegression:
def test_fromiter_comparison(self):
a = np.fromiter(list(range(10)), dtype='b')
b = np.fromiter(list(range(10)), dtype='B')
- assert_(np.alltrue(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
- assert_(np.alltrue(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
+ assert_(np.all(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
+ assert_(np.all(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
def test_fromstring_crash(self):
# Ticket #1345: the following should not cause a crash