Skip to content

Commit b54adbf

Browse files
authored
avoid dtype setting deprecated in numpy 2.5 (#718)
2 parents bdca8db + cbb07a7 commit b54adbf

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

src/stdatamodels/util.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ def gentle_asarray(a, dtype, allow_extra_columns=False):
6767
raise ValueError(msg)
6868

6969
# When a FITS file includes a pseudo-unsigned-int column, astropy will return
70-
# a FITS_rec with an incorrect table dtype. The following code rebuilds
71-
# in_dtype from the individual fields, which are correctly labeled with an
72-
# unsigned int dtype.
73-
# We can remove this once the issue is resolved in astropy:
70+
# a FITS_rec with an incorrect table dtype.
71+
# It's also unsafe to directly cast any FITS_rec with a
72+
# pseudo-unsigned column.
7473
# https://github.com/astropy/astropy/issues/8862
7574
if isinstance(a, fits.fitsrec.FITS_rec):
76-
a.dtype = _rebuild_fits_rec_dtype(a)
77-
in_dtype = a.dtype
75+
if any(c.bzero is not None for c in a.columns):
76+
return _safe_asanyarray(a, out_dtype)
7877

7978
if in_dtype == out_dtype:
8079
return a
@@ -161,7 +160,7 @@ def _safe_asanyarray(a, dtype):
161160
if any(c.bzero is not None for c in a.columns):
162161
# Due to an issue in astropy, it's not safe to directly cast
163162
# a FITS_rec with a pseudo-unsigned column.
164-
# See https://github.com/astropy/astropy/issues/12112
163+
# See https://github.com/astropy/astropy/issues/8862
165164
result = np.zeros(a.shape, dtype=dtype)
166165
for old_col, new_col in zip(a.dtype.names, result.dtype.names, strict=False):
167166
result[new_col] = a[old_col]

0 commit comments

Comments
 (0)