Description: fix test failure on 32-bit platforms.
 This fixes the following symptom while running the test suite of
 Biopython on 32-bit processors:
 .
           File "/builds/med-team/python-biopython/debian/output/source_dir/.pybuild/cpython3_3.12/build/Bio/PDB/binary_cif.py", line 85, in _run_length_decoder
             decoded_data = np.repeat(data[::2].astype(dtype), data[1::2])
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           File "/usr/lib/python3/dist-packages/numpy/core/fromnumeric.py", line 466, in repeat
             return _wrapfunc(a, 'repeat', repeats, axis=axis)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           File "/usr/lib/python3/dist-packages/numpy/core/fromnumeric.py", line 68, in _wrapfunc
             return _wrapit(obj, method, *args, **kwds)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           File "/usr/lib/python3/dist-packages/numpy/core/fromnumeric.py", line 45, in _wrapit
             result = getattr(asarray(obj), method)(*args, **kwds)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         TypeError: Cannot cast array data from dtype('uint32') to dtype('int32') according to the rule 'safe'
Author: Étienne Mollier <emollier@debian.org>
Forwarded: no
Last-Update: 2024-09-16
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- python-biopython.orig/Bio/PDB/binary_cif.py
+++ python-biopython/Bio/PDB/binary_cif.py
@@ -3,6 +3,7 @@
 """
 
 import gzip
+import sys
 from collections import deque
 from typing import Optional
 
@@ -82,7 +83,14 @@
 
     data = column["data"]["data"]
     dtype = _dtypes[encoding["srcType"]]
-    decoded_data = np.repeat(data[::2].astype(dtype), data[1::2])
+    if sys.maxsize == 2**63 - 1:
+        # We're running classical 64-bit platform here.
+        decoded_data = np.repeat(data[::2].astype(dtype), data[1::2])
+    else:
+        # We're assuming 32-bit platform here, numpy croaks on unsafe
+        # type casts.
+        decoded_data = np.repeat(data[::2].astype('int32', casting='unsafe'),
+                                 data[1::2].astype('int32', casting='unsafe'))
 
     assert len(decoded_data) == encoding["srcSize"]
     column["data"]["data"] = decoded_data
