summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2020-10-02 16:09:34 +0300
committerGitHub <noreply@github.com>2020-10-02 16:09:34 +0300
commitd19c664c70a3bcdd728a2a78bfe424491bdf2fc0 (patch)
tree60caf36a0fa08bad3109cefc27d3aad87ff82475
parent5165c654dbb2b08e8a38ac437ab35611726bf26b (diff)
parentc71edcec18d2fdbe391822e7658db43d783e8db0 (diff)
downloadnumpy-d19c664c70a3bcdd728a2a78bfe424491bdf2fc0.tar.gz
Merge pull request #17422 from joe733/hotfix-for-nested-try
MAINT: chains nested try-except in numpy/ma/core.py
-rw-r--r--numpy/ma/core.py8
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)