From 3ec9d675a40fb8a7dc8f361870e3710b940553de Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Wed, 15 Apr 2020 14:50:31 +0100 Subject: BUG: Avoid duplication in stack trace of `linspace(a, b, num=1.5)` Before this commit, the stack trace was: ``` Traceback (most recent call last): File "C:\Users\wiese\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\function_base.py", line 114, in linspace num = operator.index(num) TypeError: 'float' object cannot be interpreted as an integer During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in np.linspace(1, 2, 1.5) File "<__array_function__ internals>", line 5, in linspace File "C:\Users\wiese\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\function_base.py", line 116, in linspace raise TypeError( TypeError: object of type cannot be safely interpreted as an integer. ``` Now it is ``` Traceback (most recent call last): File "C:\Users\wiese\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\function_base.py", line 114, in linspace num = operator.index(num) TypeError: 'float' object cannot be interpreted as an integer ``` This noisy traceback was introduced in f4dfe833e3e037bb69113f7250fad3699f918cfc. --- numpy/core/function_base.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'numpy/core/function_base.py') diff --git a/numpy/core/function_base.py b/numpy/core/function_base.py index 6d49b9055..9e46f0ea5 100644 --- a/numpy/core/function_base.py +++ b/numpy/core/function_base.py @@ -110,13 +110,7 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, >>> plt.show() """ - try: - num = operator.index(num) - except TypeError: - raise TypeError( - "object of type {} cannot be safely interpreted as an integer." - .format(type(num))) - + num = operator.index(num) if num < 0: raise ValueError("Number of samples, %s, must be non-negative." % num) div = (num - 1) if endpoint else num -- cgit v1.2.1