diff options
author | keremh <hallackerem@gmail.com> | 2020-04-24 12:30:28 +0300 |
---|---|---|
committer | keremh <hallackerem@gmail.com> | 2020-04-24 14:31:13 +0300 |
commit | ddf0191ea43d763c784dcb5f7ab937d8ef1ae0b0 (patch) | |
tree | a18617e807f9a9b2705ba6af46dd9006d5dffef0 | |
parent | 6d6df47fefdc503fbcffd8cb14a5daaa956ef220 (diff) | |
download | numpy-ddf0191ea43d763c784dcb5f7ab937d8ef1ae0b0.tar.gz |
ENH: Fix exception causes in four .py files
-rw-r--r-- | numpy/lib/histograms.py | 4 | ||||
-rw-r--r-- | numpy/lib/index_tricks.py | 4 | ||||
-rw-r--r-- | numpy/lib/shape_base.py | 4 | ||||
-rw-r--r-- | numpy/lib/ufunclike.py | 8 |
4 files changed, 10 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..538b32ea2 100644 --- a/numpy/lib/index_tricks.py +++ b/numpy/lib/index_tricks.py @@ -368,8 +368,8 @@ 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..c1b520f67 100644 --- a/numpy/lib/shape_base.py +++ b/numpy/lib/shape_base.py @@ -372,8 +372,8 @@ 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) |