summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/numeric.py4
-rw-r--r--numpy/core/tests/test_numeric.py6
2 files changed, 9 insertions, 1 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index 0b728f804..a672fdc53 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -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.
@@ -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 = []
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py
index 34be84135..7309cf224 100644
--- a/numpy/core/tests/test_numeric.py
+++ b/numpy/core/tests/test_numeric.py
@@ -1044,6 +1044,12 @@ class TestBaseRepr(TestCase):
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):