From 7cf643feb91774059b29a85306b87c2eab9de67f Mon Sep 17 00:00:00 2001 From: Tuomas Rossi Date: Mon, 17 Jun 2024 14:36:00 +0300 Subject: [PATCH] Fix integer range check in NumPy 2.0 --- rdata/unparser/_xdr.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rdata/unparser/_xdr.py b/rdata/unparser/_xdr.py index 1593a7a..8bea3f0 100644 --- a/rdata/unparser/_xdr.py +++ b/rdata/unparser/_xdr.py @@ -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)