From 89cfcf0a31f07dfd33dd0b462619e7202d807b6b Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Wed, 29 Jun 2022 08:15:15 -0700 Subject: MAINT: Use Python integers for int to array of uint32 calculation The new weak promotion preserves the original type, this makes the `//= 2**32` fail for certain inputs. The alternative would be typing that as `np.int64(2**32)`, but using Python integers seems easier and cleaner. The code was effectively OK before, since the inputs were guaranteed signed (or Python integers) at that point and 2**32 would have been considered like a NumPy `int64`. (Which would be an alternative fix.) --- numpy/random/bit_generator.pyx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/numpy/random/bit_generator.pyx b/numpy/random/bit_generator.pyx index c698f6b61..3da4fabce 100644 --- a/numpy/random/bit_generator.pyx +++ b/numpy/random/bit_generator.pyx @@ -68,12 +68,12 @@ def _int_to_uint32_array(n): raise ValueError("expected non-negative integer") if n == 0: arr.append(np.uint32(n)) - if isinstance(n, np.unsignedinteger): - # Cannot do n & MASK32, convert to python int - n = int(n) + + # NumPy ints may not like `n & MASK32` or ``//= 2**32` so use Python int + n = int(n) while n > 0: arr.append(np.uint32(n & MASK32)) - n //= (2**32) + n //= 2**32 return np.array(arr, dtype=np.uint32) def _coerce_to_uint32_array(x): -- cgit v1.2.1