summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilip Ter <filip.ter@gmail.com>2021-03-23 15:52:45 -0700
committerFilip Ter <filip.ter@gmail.com>2021-03-24 15:50:49 -0700
commit0d5eefb1ebd05f3d4aeaf2572460afe9d027aa8f (patch)
tree1754ab0ab851ef4381c97e87934df0987098cd49
parentbf72d67a8b02fe06ba1efa634cff1c9f6f26a39c (diff)
downloadnumpy-0d5eefb1ebd05f3d4aeaf2572460afe9d027aa8f.tar.gz
MAINT: Adding exception chaining and switching to fstring
-rw-r--r--numpy/lib/function_base.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index ddc919e4f..6921e3df1 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -675,8 +675,8 @@ def select(condlist, choicelist, default=0):
try:
intermediate_dtype = np.result_type(*choicelist)
except TypeError as e:
- raise TypeError('Choicelist elements do not have a common dtype: {}'
- .format(e))
+ msg = f'Choicelist elements do not have a common dtype: {e}'
+ raise TypeError(msg) from None
default_array = np.asarray(default)
choicelist.append(default_array)
@@ -685,9 +685,8 @@ def select(condlist, choicelist, default=0):
try:
dtype = np.result_type(intermediate_dtype, default_array)
except TypeError as e:
- raise TypeError(
- 'Choicelists and default do not have a common dtype: {}'
- .format(e))
+ msg = f'Choicelists and default value do not have a common dtype: {e}'
+ raise TypeError(msg) from None
# Convert conditions to arrays and broadcast conditions and choices
# as the shape is needed for the result. Doing it separately optimizes