From 43d4aa5de8a991fa40c9976280cef5b4b080a806 Mon Sep 17 00:00:00 2001 From: Bertrand Date: Wed, 8 Jul 2015 22:45:05 -0400 Subject: EHN: raise error for negative 'num' in linspace. Closing #5937 --- numpy/core/function_base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'numpy/core/function_base.py') 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 -- cgit v1.2.1