Skip to content

Commit

Permalink
Fix integer range check in NumPy 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
trossi committed Jun 17, 2024
1 parent 42ac9b8 commit 7cf643f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rdata/unparser/_xdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def _unparse_array_values(self, array: npt.NDArray[Any]) -> None:
mask = np.ma.getmask(array) # type: ignore [no-untyped-call]
array = np.ma.getdata(array).copy() # type: ignore [no-untyped-call]
array[mask] = R_INT_NA
if not np.all([np.can_cast(val, np.int32) for val in array]):
info = np.iinfo(np.int32)
if not all(info.min <= val <= info.max for val in array):
msg = "Integer array not castable to int32"
raise ValueError(msg)
array = array.astype(np.int32)
Expand Down

0 comments on commit 7cf643f

Please sign in to comment.