diff options
author | Jovial Joe Jayarson <jovial7joe@hotmail.com> | 2020-10-02 11:02:54 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-02 11:02:54 +0530 |
commit | c71edcec18d2fdbe391822e7658db43d783e8db0 (patch) | |
tree | f9e947900aae30ca11ed483ce9917bb69bb666b8 | |
parent | 57adb4bb6a8eb46fed597d4a781e47bcb86ebe11 (diff) | |
download | numpy-c71edcec18d2fdbe391822e7658db43d783e8db0.tar.gz |
fix: chains nested try-except-raise
-rw-r--r-- | numpy/ma/core.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index b5371f51a..4e320576b 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -443,9 +443,9 @@ def _check_fill_value(fill_value, ndtype): if isinstance(fill_value, (ndarray, np.void)): try: fill_value = np.array(fill_value, copy=False, dtype=ndtype) - except ValueError: + except ValueError as e: err_msg = "Unable to transform %s to dtype %s" - raise ValueError(err_msg % (fill_value, ndtype)) + raise ValueError(err_msg % (fill_value, ndtype)) from e else: fill_value = np.asarray(fill_value, dtype=object) fill_value = np.array(_recursive_set_fill_value(fill_value, ndtype), @@ -460,12 +460,12 @@ def _check_fill_value(fill_value, ndtype): # Also in case of converting string arrays. try: fill_value = np.array(fill_value, copy=False, dtype=ndtype) - except (OverflowError, ValueError): + except (OverflowError, ValueError) as e: # Raise TypeError instead of OverflowError or ValueError. # OverflowError is seldom used, and the real problem here is # that the passed fill_value is not compatible with the ndtype. err_msg = "Cannot convert fill_value %s to dtype %s" - raise TypeError(err_msg % (fill_value, ndtype)) + raise TypeError(err_msg % (fill_value, ndtype)) from e return np.array(fill_value) |