8000 Check lower base limit in base_repr. by nbeaver · Pull Request #6298 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Check lower base limit in base_repr. #6298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion numpy/core/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -2198,7 +2198,7 @@ def base_repr(number, base=2, padding=0):
Parameters
----------
number : int
The value to convert. Only positive values are handled.
The value to convert. Positive and negative values are handled.
base : int, optional
Convert `number` to the `base` number system. The valid range is 2-36,
the default value is 2.
Expand Down Expand Up @@ -2232,6 +2232,8 @@ def base_repr(number, base=2, padding=0):
digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
if base > len(digits):
raise ValueError("Bases greater than 36 not handled in base_repr.")
elif base < 2:
raise ValueError("Bases less than 2 not handled in base_repr.")

num = abs(number)
res = []
Expand Down
6 changes: 6 additions & 0 deletions numpy/core/tests/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,12 @@ def test_negative(self):
assert_equal(np.base_repr(-12, 10, 4), '-000012')
assert_equal(np.base_repr(-12, 4), '-30')

def test_base_range(self):
with self.assertRaises(ValueError):
np.base_repr(1, 1)
with self.assertRaises(ValueError):
np.base_repr(1, 37)


class TestArrayComparisons(TestCase):
def test_array_equal(self):
Expand Down
0