diff options
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/histograms.py | 4 | ||||
-rw-r--r-- | numpy/lib/index_tricks.py | 6 | ||||
-rw-r--r-- | numpy/lib/shape_base.py | 6 | ||||
-rw-r--r-- | numpy/lib/ufunclike.py | 8 |
4 files changed, 14 insertions, 10 deletions
diff --git a/numpy/lib/histograms.py b/numpy/lib/histograms.py index ede8a26e4..f080cc392 100644 --- a/numpy/lib/histograms.py +++ b/numpy/lib/histograms.py @@ -417,9 +417,9 @@ def _get_bin_edges(a, bins, range, weights): elif np.ndim(bins) == 0: try: n_equal_bins = operator.index(bins) - except TypeError: + except TypeError as e: raise TypeError( - '`bins` must be an integer, a string, or an array') + '`bins` must be an integer, a string, or an array') from e if n_equal_bins < 1: raise ValueError('`bins` must be positive, when an integer') diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py index b4118814d..d145477c3 100644 --- a/numpy/lib/index_tricks.py +++ b/numpy/lib/index_tricks.py @@ -368,8 +368,10 @@ class AxisConcatenator: if len(vec) == 3: trans1d = int(vec[2]) continue - except Exception: - raise ValueError("unknown special directive") + except Exception as e: + raise ValueError( + "unknown special directive {!r}".format(item) + ) from e try: axis = int(item) continue diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py index b7f1f16f2..72a7f79d7 100644 --- a/numpy/lib/shape_base.py +++ b/numpy/lib/shape_base.py @@ -372,8 +372,10 @@ def apply_along_axis(func1d, axis, arr, *args, **kwargs): # invoke the function on the first item try: ind0 = next(inds) - except StopIteration: - raise ValueError('Cannot apply_along_axis when any iteration dimensions are 0') + except StopIteration as e: + raise ValueError( + 'Cannot apply_along_axis when any iteration dimensions are 0' + ) from None res = asanyarray(func1d(inarr_view[ind0], *args, **kwargs)) # build a buffer for storing evaluations of func1d. diff --git a/numpy/lib/ufunclike.py b/numpy/lib/ufunclike.py index 8512669c2..1f26a1845 100644 --- a/numpy/lib/ufunclike.py +++ b/numpy/lib/ufunclike.py @@ -188,9 +188,9 @@ def isposinf(x, out=None): is_inf = nx.isinf(x) try: signbit = ~nx.signbit(x) - except TypeError: + except TypeError as e: raise TypeError('This operation is not supported for complex values ' - 'because it would be ambiguous.') + 'because it would be ambiguous.') from e else: return nx.logical_and(is_inf, signbit, out) @@ -259,8 +259,8 @@ def isneginf(x, out=None): is_inf = nx.isinf(x) try: signbit = nx.signbit(x) - except TypeError: + except TypeError as e: raise TypeError('This operation is not supported for complex values ' - 'because it would be ambiguous.') + 'because it would be ambiguous.') from e else: return nx.logical_and(is_inf, signbit, out) |