Skip to content

Commit 4d5b9bc

Browse files
committed
BUG: Allow unsigned shift argument for np.roll
1 parent e759d24 commit 4d5b9bc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

numpy/_core/numeric.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ def roll(a, shift, axis=None):
12931293
"'shift' and 'axis' should be scalars or 1D sequences")
12941294
shifts = {ax: 0 for ax in range(a.ndim)}
12951295
for sh, ax in broadcasted:
1296-
shifts[ax] += sh
1296+
shifts[ax] += int(sh)
12971297

12981298
rolls = [((slice(None), slice(None)),)] * a.ndim
12991299
for ax, offset in shifts.items():

numpy/_core/tests/test_numeric.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3703,6 +3703,18 @@ def test_roll_empty(self):
37033703
x = np.array([])
37043704
assert_equal(np.roll(x, 1), np.array([]))
37053705

3706+
def test_roll_unsigned_shift(self):
3707+
x = np.arange(4)
3708+
shift = np.uint16(2)
3709+
assert_equal(np.roll(x, shift), np.roll(x, 2))
3710+
3711+
shift = np.uint64(2**63+2)
3712+
assert_equal(np.roll(x, shift), np.roll(x, 2))
3713+
3714+
def test_roll_big_int(self):
3715+
x = np.arange(4)
3716+
assert_equal(np.roll(x, 2**100), x)
3717+
37063718

37073719
class TestRollaxis:
37083720

0 commit comments

Comments
 (0)