Skip to content

Commit 57a66fc

Browse files
SWE-bench ComplexAnthony Shaw
authored andcommitted
Human gold patch for astropy__astropy-19128
PR: astropy#19128 Issue: astropy#19126 Base commit: 108d07d Changed lines: 21
1 parent 108d07d commit 57a66fc

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎astropy/io/fits/tests/test_image.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from numpy.testing import assert_equal
1010

1111
from astropy.io import fits
12+
from astropy.utils.compat import NUMPY_LT_2_5
1213
from astropy.utils.data import get_pkg_data_filename
1314
from astropy.utils.exceptions import AstropyUserWarning
1415

@@ -977,7 +978,12 @@ def test_open_scaled_in_update_mode(self):
977978

978979
# Try reshaping the data, then closing and reopening the file; let's
979980
# see if all the changes are preserved properly
980-
hdul[0].data.shape = (42, 10)
981+
if NUMPY_LT_2_5:
982+
hdul[0].data.shape = (42, 10)
983+
else:
984+
# ndarray._set_shape is semi-private, but the only
985+
# non deprecated, strict semantic equivalent in Numpy 2.5+
986+
hdul[0].data._set_shape((42, 10))
981987
hdul.close()
982988

983989
hdul = fits.open(testfile)
@@ -988,6 +994,13 @@ def test_open_scaled_in_update_mode(self):
988994
assert "BSCALE" not in hdul[0].header
989995
hdul.close()
990996

997+
with fits.open(testfile, mode="update") as hdul:
998+
# Try reshaping the data again, this time using np.reshape
999+
hdul[0].data = np.reshape(hdul[0].data, (21, 20))
1000+
1001+
with fits.open(testfile) as hdul:
1002+
assert hdul[0].shape == (21, 20)
1003+
9911004
def test_scale_back(self):
9921005
"""A simple test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/120
9931006

‎astropy/io/fits/util.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from packaging.version import Version
2121

2222
from astropy.utils import data
23+
from astropy.utils.compat import NUMPY_LT_2_5
2324
from astropy.utils.compat.optional_deps import HAS_DASK
2425
from astropy.utils.exceptions import AstropyUserWarning
2526

@@ -870,7 +871,10 @@ def _rstrip_inplace(array):
870871
# Note: the code will work if this fails; the chunks will just be larger.
871872
if b.ndim > 2:
872873
try:
873-
b.shape = -1, b.shape[-1]
874+
if NUMPY_LT_2_5:
875+
b.shape = -1, b.shape[-1]
876+
else:
877+
b._set_shape((-1, b.shape[-1]))
874878
except AttributeError: # can occur for non-contiguous arrays
875879
pass
876880
for j in range(0, b.shape[0], bufsize):

0 commit comments

Comments
 (0)