Skip to content

Commit

Permalink
Merge pull request #26162 from krisrosengreen/base_repr_fix
Browse files Browse the repository at this point in the history
BUG: Infinite Loop in numpy.base_repr
  • Loading branch information
ngoldbaum committed Mar 29, 2024
2 parents b425f6d + 79d3552 commit ef6299c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion numpy/_core/numeric.py
Expand Up @@ -2142,7 +2142,7 @@ def base_repr(number, base=2, padding=0):
elif base < 2:
raise ValueError("Bases less than 2 not handled in base_repr.")

num = abs(number)
num = abs(int(number))
res = []
while num:
res.append(digits[num % base])
Expand Down
3 changes: 3 additions & 0 deletions numpy/_core/tests/test_numeric.py
Expand Up @@ -1969,6 +1969,9 @@ def test_base_range(self):
with assert_raises(ValueError):
np.base_repr(1, 37)

def test_minimal_signed_int(self):
assert_equal(np.base_repr(np.int8(-128)), '-10000000')


def _test_array_equal_parametrizations():
"""
Expand Down

0 comments on commit ef6299c

Please sign in to comment.