Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/release/upcoming_changes/23314.deprecation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* ``np.product`` is deprecated. Use `np.prod` instead.
* ``np.cumproduct`` is deprecated. Use `np.cumprod` instead.
* ``np.sometrue`` is deprecated. Use `np.any` instead.
* ``np.alltrue`` is deprecated. Use `np.all` instead.
33 changes: 33 additions & 0 deletions numpy/core/fromnumeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)


Expand All @@ -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)


Expand All @@ -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)


Expand All @@ -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)
19 changes: 17 additions & 2 deletions numpy/core/tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])))
2 changes: 1 addition & 1 deletion numpy/core/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ def _get_multi_index(self, arr, indices):
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:
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/tests/test_mem_overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions numpy/core/tests/test_memmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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 (
Expand Down Expand Up @@ -153,7 +153,7 @@ def test_ufunc_return_ndarray(self):

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__)
Expand Down
8 changes: 5 additions & 3 deletions numpy/core/tests/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ def test_count_nonzero(self):

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],
Expand Down Expand Up @@ -1193,8 +1195,8 @@ def test_values(self):
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.
Expand Down
23 changes: 8 additions & 15 deletions numpy/core/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,22 +516,15 @@ def test_void_copyswap(self):
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
Expand Down Expand Up @@ -1336,8 +1329,8 @@ def test_fromiter_bytes(self):
# 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
Expand Down Expand Up @@ -1515,8 +1508,8 @@ def test_log1p_compiler_shenanigans(self):
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
Expand Down
19 changes: 9 additions & 10 deletions numpy/lib/index_tricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import math
import warnings

import numpy as np
from .._utils import set_module
import numpy.core.numeric as _nx
from numpy.core.numeric import (
asarray, ScalarType, array, alltrue, cumprod, arange, ndim
)
from numpy.core.numeric import ScalarType, array
from numpy.core.numerictypes import find_common_type, issubdtype

import numpy.matrixlib as matrixlib
Expand Down Expand Up @@ -94,7 +93,7 @@ def ix_(*args):
nd = len(args)
for k, new in enumerate(args):
if not isinstance(new, _nx.ndarray):
new = asarray(new)
new = np.asarray(new)
if new.size == 0:
# Explicitly type empty arrays to avoid float default
new = new.astype(_nx.intp)
Expand Down Expand Up @@ -396,7 +395,7 @@ def __getitem__(self, key):
scalar = True
scalartypes.append(newobj.dtype)
else:
item_ndim = ndim(item)
item_ndim = np.ndim(item)
newobj = array(item, copy=False, subok=True, ndmin=ndmin)
if trans1d != -1 and item_ndim < ndmin:
k2 = ndmin - item_ndim
Expand Down Expand Up @@ -596,7 +595,7 @@ class ndenumerate:
"""

def __init__(self, arr):
self.iter = asarray(arr).flat
self.iter = np.asarray(arr).flat

def __next__(self):
"""
Expand Down Expand Up @@ -909,9 +908,9 @@ def fill_diagonal(a, val, wrap=False):
else:
# For more than d=2, the strided formula is only valid for arrays with
# all dimensions equal, so we check first.
if not alltrue(diff(a.shape) == 0):
if not np.all(diff(a.shape) == 0):
raise ValueError("All dimensions of input must be of equal length")
step = 1 + (cumprod(a.shape[:-1])).sum()
step = 1 + (np.cumprod(a.shape[:-1])).sum()

# Write the value out into the diagonal.
a.flat[:end:step] = val
Expand Down Expand Up @@ -982,7 +981,7 @@ def diag_indices(n, ndim=2):
[0, 1]]])

"""
idx = arange(n)
idx = np.arange(n)
return (idx,) * ndim


Expand Down Expand Up @@ -1041,7 +1040,7 @@ def diag_indices_from(arr):
raise ValueError("input array must be at least 2-d")
# For more than d=2, the strided formula is only valid for arrays with
# all dimensions equal, so we check first.
if not alltrue(diff(arr.shape) == 0):
if not np.all(diff(arr.shape) == 0):
raise ValueError("All dimensions of input must be of equal length")

return diag_indices(arr.shape[0], arr.ndim)
8 changes: 4 additions & 4 deletions numpy/lib/tests/test_function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ def test_basic(self):
def test_nd(self):
y1 = [[0, 0, 0], [0, 1, 0], [1, 1, 0]]
assert_(np.any(y1))
assert_array_equal(np.sometrue(y1, axis=0), [1, 1, 0])
assert_array_equal(np.sometrue(y1, axis=1), [0, 1, 1])
assert_array_equal(np.any(y1, axis=0), [1, 1, 0])
assert_array_equal(np.any(y1, axis=1), [0, 1, 1])


class TestAll:
Expand All @@ -247,8 +247,8 @@ def test_basic(self):
def test_nd(self):
y1 = [[0, 0, 1], [0, 1, 1], [1, 1, 1]]
assert_(not np.all(y1))
assert_array_equal(np.alltrue(y1, axis=0), [0, 0, 1])
assert_array_equal(np.alltrue(y1, axis=1), [0, 0, 1])
assert_array_equal(np.all(y1, axis=0), [0, 0, 1])
assert_array_equal(np.all(y1, axis=1), [0, 0, 1])


class TestCopy:
Expand Down
2 changes: 1 addition & 1 deletion numpy/lib/tests/test_type_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class TestIscomplex:
def test_fail(self):
z = np.array([-1, 0, 1])
res = iscomplex(z)
assert_(not np.sometrue(res, axis=0))
assert_(not np.any(res, axis=0))

def test_pass(self):
z = np.array([-1j, 1, 0])
Expand Down
4 changes: 2 additions & 2 deletions numpy/linalg/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
array, asarray, zeros, empty, empty_like, intc, single, double,
csingle, cdouble, inexact, complexfloating, newaxis, all, Inf, dot,
add, multiply, sqrt, sum, isfinite,
finfo, errstate, geterrobj, moveaxis, amin, amax, product, abs,
finfo, errstate, geterrobj, moveaxis, amin, amax, prod, abs,
atleast_2d, intp, asanyarray, object_, matmul,
swapaxes, divide, count_nonzero, isnan, sign, argsort, sort,
reciprocal
Expand Down Expand Up @@ -196,7 +196,7 @@ def _assert_finite(*arrays):

def _is_empty_2d(arr):
# check size first for efficiency
return arr.size == 0 and product(arr.shape[-2:]) == 0
return arr.size == 0 and prod(arr.shape[-2:]) == 0


def transpose(a):
Expand Down
4 changes: 2 additions & 2 deletions numpy/ma/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def apply_along_axis(func1d, axis, arr, *args, **kwargs):
dtypes.append(np.asarray(res).dtype)
outarr = zeros(outshape, object)
outarr[tuple(ind)] = res
Ntot = np.product(outshape)
Ntot = np.prod(outshape)
k = 1
while k < Ntot:
# increment the index
Expand All @@ -418,7 +418,7 @@ def apply_along_axis(func1d, axis, arr, *args, **kwargs):
j = i.copy()
j[axis] = ([slice(None, None)] * res.ndim)
j.put(indlist, ind)
Ntot = np.product(outshape)
Ntot = np.prod(outshape)
holdshape = outshape
outshape = list(arr.shape)
outshape[axis] = res.shape
Expand Down
8 changes: 4 additions & 4 deletions numpy/ma/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,16 +1336,16 @@ def test_addsumprod(self):
assert_equal(np.sum(x, axis=0), sum(x, axis=0))
assert_equal(np.sum(filled(xm, 0), axis=0), sum(xm, axis=0))
assert_equal(np.sum(x, 0), sum(x, 0))
assert_equal(np.product(x, axis=0), product(x, axis=0))
assert_equal(np.product(x, 0), product(x, 0))
assert_equal(np.product(filled(xm, 1), axis=0), product(xm, axis=0))
assert_equal(np.prod(x, axis=0), product(x, axis=0))
assert_equal(np.prod(x, 0), product(x, 0))
assert_equal(np.prod(filled(xm, 1), axis=0), product(xm, axis=0))
s = (3, 4)
x.shape = y.shape = xm.shape = ym.shape = s
if len(s) > 1:
assert_equal(np.concatenate((x, y), 1), concatenate((xm, ym), 1))
assert_equal(np.add.reduce(x, 1), add.reduce(x, 1))
assert_equal(np.sum(x, 1), sum(x, 1))
assert_equal(np.product(x, 1), product(x, 1))
assert_equal(np.prod(x, 1), product(x, 1))

def test_binops_d2D(self):
# Test binary operations on 2D data
Expand Down
8 changes: 4 additions & 4 deletions numpy/ma/tests/test_old_ma.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,16 @@ def test_testAddSumProd(self):
assert_(eq(np.sum(x, axis=0), sum(x, axis=0)))
assert_(eq(np.sum(filled(xm, 0), axis=0), sum(xm, axis=0)))
assert_(eq(np.sum(x, 0), sum(x, 0)))
assert_(eq(np.product(x, axis=0), product(x, axis=0)))
assert_(eq(np.product(x, 0), product(x, 0)))
assert_(eq(np.product(filled(xm, 1), axis=0),
assert_(eq(np.prod(x, axis=0), product(x, axis=0)))
assert_(eq(np.prod(x, 0), product(x, 0)))
assert_(eq(np.prod(filled(xm, 1), axis=0),
product(xm, axis=0)))
if len(s) > 1:
assert_(eq(np.concatenate((x, y), 1),
concatenate((xm, ym), 1)))
assert_(eq(np.add.reduce(x, 1), add.reduce(x, 1)))
assert_(eq(np.sum(x, 1), sum(x, 1)))
assert_(eq(np.product(x, 1), product(x, 1)))
assert_(eq(np.prod(x, 1), product(x, 1)))

def test_testCI(self):
# Test of conversions and indexing
Expand Down
Loading