summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/memmap.py8
-rw-r--r--numpy/ma/core.py6
2 files changed, 9 insertions, 5 deletions
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py
index ad66446c2..cb025736e 100644
--- a/numpy/core/memmap.py
+++ b/numpy/core/memmap.py
@@ -209,10 +209,12 @@ class memmap(ndarray):
import os.path
try:
mode = mode_equivalents[mode]
- except KeyError:
+ except KeyError as e:
if mode not in valid_filemodes:
- raise ValueError("mode must be one of %s" %
- (valid_filemodes + list(mode_equivalents.keys())))
+ raise ValueError(
+ "mode must be one of {!r} (got {!r})"
+ .format(valid_filemodes + list(mode_equivalents.keys()), mode)
+ ) from None
if mode == 'w+' and shape is None:
raise ValueError("shape must be given")
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index a5e59bb74..a7214f9bf 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -285,8 +285,10 @@ def _extremum_fill_value(obj, extremum, extremum_name):
def _scalar_fill_value(dtype):
try:
return extremum[dtype]
- except KeyError:
- raise TypeError(f"Unsuitable type {dtype} for calculating {extremum_name}.")
+ except KeyError as e:
+ raise TypeError(
+ f"Unsuitable type {dtype} for calculating {extremum_name}."
+ ) from None
dtype = _get_dtype_of(obj)
return _recursive_fill_value(dtype, _scalar_fill_value)