summaryrefslogtreecommitdiff
path: root/numpy/core/arrayprint.py
diff options
context:
space:
mode:
authorMitchell Faas <Faas.Mitchell@gmail.com>2021-01-31 00:51:28 +0100
committerMitchell Faas <Faas.Mitchell@gmail.com>2021-01-31 00:51:28 +0100
commitef639359f4862762d97c215990f86a7a622c0f0d (patch)
tree120dedf1146af08fde4128224b3844de24c7ca62 /numpy/core/arrayprint.py
parent48808e1a6a775283b2d482d65f93390ddeb534af (diff)
downloadnumpy-ef639359f4862762d97c215990f86a7a622c0f0d.tar.gz
ENH: Added sanity check to printoptions
See issue #18254
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r--numpy/core/arrayprint.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
index 3fade4824..2d772c778 100644
--- a/numpy/core/arrayprint.py
+++ b/numpy/core/arrayprint.py
@@ -78,6 +78,7 @@ def _make_options_dict(precision=None, threshold=None, edgeitems=None,
if legacy not in [None, False, '1.13']:
warnings.warn("legacy printing option can currently only be '1.13' or "
"`False`", stacklevel=3)
+
if threshold is not None:
# forbid the bad threshold arg suggested by stack overflow, gh-12351
if not isinstance(threshold, numbers.Number):
@@ -85,6 +86,12 @@ def _make_options_dict(precision=None, threshold=None, edgeitems=None,
if np.isnan(threshold):
raise ValueError("threshold must be non-NAN, try "
"sys.maxsize for untruncated representation")
+
+ if precision is not None:
+ # forbid the bad precision arg as suggested by issue #18254
+ if not isinstance(precision, int):
+ raise TypeError('precision must be an integer')
+
return options