diff options
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/function_base.py | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_function_base.py | 1 |
2 files changed, 4 insertions, 1 deletions
diff --git a/numpy/core/function_base.py b/numpy/core/function_base.py index e50e1a505..532ef2950 100644 --- a/numpy/core/function_base.py +++ b/numpy/core/function_base.py @@ -25,7 +25,7 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None): evenly spaced samples, so that `stop` is excluded. Note that the step size changes when `endpoint` is False. num : int, optional - Number of samples to generate. Default is 50. + Number of samples to generate. Default is 50. Must be non-negative. endpoint : bool, optional If True, `stop` is the last sample. Otherwise, it is not included. Default is True. @@ -82,6 +82,8 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None): """ num = int(num) + if num < 0: + raise ValueError("Number of samples, %s, must be non-negative." % num) div = (num - 1) if endpoint else num # Convert float/complex array scalars to float, gh-3504 diff --git a/numpy/core/tests/test_function_base.py b/numpy/core/tests/test_function_base.py index a64d44473..aba030f3d 100644 --- a/numpy/core/tests/test_function_base.py +++ b/numpy/core/tests/test_function_base.py @@ -34,6 +34,7 @@ class TestLinspace(TestCase): assert_(y[-1] == 10) y = linspace(2, 10, endpoint=0) assert_(y[-1] < 10) + assert_raises(ValueError, linspace, 0, 10, num=-1) def test_corner(self): y = list(linspace(0, 1, 1)) |