summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortabhi0797 <abhinav071197@gmail.com>2020-07-04 12:06:51 +0530
committertabhi0797 <abhinav071197@gmail.com>2020-07-04 12:06:51 +0530
commit0cd387c6513f2b5b514898c3a06947af7dd919dc (patch)
tree0458f3adf3da1f88f1f73f63416a4bb29ff54998
parent9298eeb4f6c73ca1259f627860abe98b63f89da4 (diff)
downloadnumpy-0cd387c6513f2b5b514898c3a06947af7dd919dc.tar.gz
MAINT: Chaining exceptions in numpy/core/_internal.py
- updated %formatted string to f strings
-rw-r--r--numpy/core/_internal.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py
index 1378497bb..f194b4e86 100644
--- a/numpy/core/_internal.py
+++ b/numpy/core/_internal.py
@@ -161,9 +161,10 @@ def _commastring(astr):
mo = format_re.match(astr, pos=startindex)
try:
(order1, repeats, order2, dtype) = mo.groups()
- except (TypeError, AttributeError):
- raise ValueError('format number %d of "%s" is not recognized' %
- (len(result)+1, astr))
+ except (TypeError, AttributeError) as e:
+ raise ValueError(
+ f'format number {len(result)+1} of "{astr}" is not recognized'
+ ) from e
startindex = mo.end()
# Separator or ending padding
if startindex < len(astr):
@@ -371,11 +372,11 @@ def _newnames(datatype, order):
for name in order:
try:
nameslist.remove(name)
- except ValueError:
+ except ValueError as e:
if name in seen:
- raise ValueError("duplicate field name: %s" % (name,))
+ raise ValueError(f"duplicate field name: {name}") from e
else:
- raise ValueError("unknown field name: %s" % (name,))
+ raise ValueError(f"unknown field name: {name}") from e
seen.add(name)
return tuple(list(order) + nameslist)
raise ValueError("unsupported order value: %s" % (order,))