Skip to content

Commit

Permalink
Merge pull request #14520 from mhvk/auto-backport-of-pr-14510-on-v5.2.x
Browse files Browse the repository at this point in the history
Backport PR #14510 on branch v5.2.x (Fix numpy 1.25 deprecation warnings.)
  • Loading branch information
mhvk committed Mar 12, 2023
2 parents 9173412 + 4107e5f commit 2ff59cc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
12 changes: 6 additions & 6 deletions astropy/convolution/convolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ def convolve_fft(
kernshape = kernel.shape

array_size_B = (
np.product(arrayshape, dtype=np.int64) * np.dtype(complex_dtype).itemsize
np.prod(arrayshape, dtype=np.int64) * np.dtype(complex_dtype).itemsize
) * u.byte
if array_size_B > 1 * u.GB and not allow_huge:
raise ValueError(
Expand Down Expand Up @@ -840,7 +840,7 @@ def convolve_fft(

# perform a second check after padding
array_size_C = (
np.product(newshape, dtype=np.int64) * np.dtype(complex_dtype).itemsize
np.prod(newshape, dtype=np.int64) * np.dtype(complex_dtype).itemsize
) * u.byte
if array_size_C > 1 * u.GB and not allow_huge:
raise ValueError(
Expand All @@ -854,12 +854,12 @@ def convolve_fft(
# (kernel*array)fft +
# optional(weight image + weight_fft + weight_ifft) +
# optional(returned_fft))
# total_memory_used_GB = (np.product(newshape)*np.dtype(complex_dtype).itemsize
# total_memory_used_GB = (np.prod(newshape)*np.dtype(complex_dtype).itemsize
# * (5 + 3*((interpolate_nan or ) and kernel_is_normalized))
# + (1 + (not return_fft)) *
# np.product(arrayshape)*np.dtype(complex_dtype).itemsize
# + np.product(arrayshape)*np.dtype(bool).itemsize
# + np.product(kernshape)*np.dtype(bool).itemsize)
# np.prod(arrayshape)*np.dtype(complex_dtype).itemsize
# + np.prod(arrayshape)*np.dtype(bool).itemsize
# + np.prod(kernshape)*np.dtype(bool).itemsize)
# ) / 1024.**3

# separate each dimension by the padding size... this is to determine the
Expand Down
2 changes: 1 addition & 1 deletion astropy/modeling/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ def test_prepare_outputs_sparse_grid():
"""

shape = (3, 3)
data = np.arange(np.product(shape)).reshape(shape) * u.m / u.s
data = np.arange(np.prod(shape)).reshape(shape) * u.m / u.s

points_unit = u.pix
points = [np.arange(size) * points_unit for size in shape]
Expand Down
20 changes: 12 additions & 8 deletions astropy/units/tests/test_quantity_non_ufuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
TBD_FUNCTIONS,
UNSUPPORTED_FUNCTIONS,
)
from astropy.utils.compat import NUMPY_LT_1_23, NUMPY_LT_1_24, NUMPY_LT_1_25
from astropy.utils.compat import NUMPY_LT_1_23, NUMPY_LT_1_24

needs_array_function = pytest.mark.xfail(
not ARRAY_FUNCTION_ENABLED, reason="Needs __array_function__ support"
Expand Down Expand Up @@ -634,10 +634,14 @@ def test_all(self):
with pytest.raises(TypeError):
np.all(self.q)

# NUMPY_LT_1_25
@pytest.mark.filterwarnings("ignore:`sometrue` is deprecated as of NumPy 1.25.0")
def test_sometrue(self):
with pytest.raises(TypeError):
np.sometrue(self.q)

# NUMPY_LT_1_25
@pytest.mark.filterwarnings("ignore:`alltrue` is deprecated as of NumPy 1.25.0")
def test_alltrue(self):
with pytest.raises(TypeError):
np.alltrue(self.q)
Expand All @@ -646,6 +650,8 @@ def test_prod(self):
with pytest.raises(u.UnitsError):
np.prod(self.q)

# NUMPY_LT_1_25
@pytest.mark.filterwarnings("ignore:`product` is deprecated as of NumPy 1.25.0")
def test_product(self):
with pytest.raises(u.UnitsError):
np.product(self.q)
Expand All @@ -654,6 +660,8 @@ def test_cumprod(self):
with pytest.raises(u.UnitsError):
np.cumprod(self.q)

# NUMPY_LT_1_25
@pytest.mark.filterwarnings("ignore:`cumproduct` is deprecated as of NumPy 1.25.0")
def test_cumproduct(self):
with pytest.raises(u.UnitsError):
np.cumproduct(self.q)
Expand All @@ -667,14 +675,10 @@ def test_ptp(self):
def test_round(self):
self.check(np.round)

# NUMPY_LT_1_25
@pytest.mark.filterwarnings("ignore:`round_` is deprecated as of NumPy 1.25.0")
def test_round_(self):
if NUMPY_LT_1_25:
self.check(np.round_)
else:
with pytest.warns(
DeprecationWarning, match="`round_` is deprecated as of NumPy 1.25.0"
):
self.check(np.round_)
self.check(np.round_)

def test_around(self):
self.check(np.around)
Expand Down
18 changes: 11 additions & 7 deletions astropy/utils/masked/tests/test_function_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,21 +603,29 @@ def test_any(self):
def test_all(self):
self.check(np.all)

# NUMPY_LT_1_25
@pytest.mark.filterwarnings("ignore:`sometrue` is deprecated as of NumPy 1.25.0")
def test_sometrue(self):
self.check(np.sometrue, method="any")

# NUMPY_LT_1_25
@pytest.mark.filterwarnings("ignore:`alltrue` is deprecated as of NumPy 1.25.0")
def test_alltrue(self):
self.check(np.alltrue, method="all")

def test_prod(self):
self.check(np.prod)

# NUMPY_LT_1_25
@pytest.mark.filterwarnings("ignore:`product` is deprecated as of NumPy 1.25.0")
def test_product(self):
self.check(np.product, method="prod")

def test_cumprod(self):
self.check(np.cumprod)

# NUMPY_LT_1_25
@pytest.mark.filterwarnings("ignore:`cumproduct` is deprecated as of NumPy 1.25.0")
def test_cumproduct(self):
self.check(np.cumproduct, method="cumprod")

Expand All @@ -628,14 +636,10 @@ def test_ptp(self):
def test_round(self):
self.check(np.round, method="round")

# NUMPY_LT_1_25
@pytest.mark.filterwarnings("ignore:`round_` is deprecated as of NumPy 1.25.0")
def test_round_(self):
if NUMPY_LT_1_25:
self.check(np.round_, method="round")
else:
with pytest.warns(
DeprecationWarning, match="`round_` is deprecated as of NumPy 1.25.0"
):
self.check(np.round_, method="round")
self.check(np.round_, method="round")

def test_around(self):
self.check(np.around, method="round")
Expand Down
2 changes: 1 addition & 1 deletion examples/io/skip_create-large-fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

shape = tuple(header[f'NAXIS{ii}'] for ii in range(1, header['NAXIS']+1))
with open('large.fits', 'rb+') as fobj:
fobj.seek(len(header.tostring()) + (np.product(shape) * np.abs(header['BITPIX']//8)) - 1)
fobj.seek(len(header.tostring()) + (np.prod(shape) * np.abs(header['BITPIX']//8)) - 1)
fobj.write(b'\0')

##############################################################################
Expand Down

0 comments on commit 2ff59cc

Please sign in to comment.