Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numpy 1.25 deprecation warnings. #14510

Merged
merged 4 commits into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 6 additions & 6 deletions astropy/convolution/convolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,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 @@ -838,7 +838,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 @@ -852,12 +852,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/io/fits/_tiled_compression/tests/test_fitsio.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def base_original_data(data_shape, dtype, numpy_rng, compression_type):
# There seems to be a bug with the fitsio library where HCOMPRESS doesn't
# work with int16 random data, so use a bit for structured test data.
if compression_type.startswith("HCOMPRESS") and "i2" in dtype or "u1" in dtype:
random = np.arange(np.product(data_shape)).reshape(data_shape)
random = np.arange(np.prod(data_shape)).reshape(data_shape)
return random.astype(dtype)


Expand Down
2 changes: 1 addition & 1 deletion astropy/io/fits/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2009,7 +2009,7 @@ class TestCompHDUSections:
@pytest.fixture(autouse=True)
def setup_method(self, tmp_path):
shape = (13, 17, 25)
self.data = np.arange(np.product(shape)).reshape(shape).astype(np.int32)
self.data = np.arange(np.prod(shape)).reshape(shape).astype(np.int32)

header1 = fits.Header()
hdu1 = fits.CompImageHDU(
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
15 changes: 7 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,12 @@ def test_all(self):
with pytest.raises(TypeError):
np.all(self.q)

@pytest.mark.filterwarnings("ignore:`sometrue` is deprecated as of NumPy 1.25.0")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like removing NUMPY_LT_1_25. Makes it hard to grep and remove dead code when we eventually bump minversion to numpy 1.25. Can we at least leave # NUMPY_LT_1_25 here for future grep?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless numpy dev remove it first before that happens but I can't tell the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 done

def test_sometrue(self):
with pytest.raises(TypeError):
np.sometrue(self.q)
mhvk marked this conversation as resolved.
Show resolved Hide resolved

@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 +648,7 @@ def test_prod(self):
with pytest.raises(u.UnitsError):
np.prod(self.q)

@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)
mhvk marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -654,6 +657,7 @@ def test_cumprod(self):
with pytest.raises(u.UnitsError):
np.cumprod(self.q)

@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 +671,9 @@ def test_ptp(self):
def test_round(self):
self.check(np.round)

@pytest.mark.filterwarnings("ignore:`round_` is deprecated as of NumPy 1.25.0")
mhvk marked this conversation as resolved.
Show resolved Hide resolved
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
4 changes: 4 additions & 0 deletions astropy/utils/masked/tests/test_function_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,21 +603,25 @@ def test_any(self):
def test_all(self):
self.check(np.all)

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

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

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

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

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