From ef639359f4862762d97c215990f86a7a622c0f0d Mon Sep 17 00:00:00 2001 From: Mitchell Faas Date: Sun, 31 Jan 2021 00:51:28 +0100 Subject: ENH: Added sanity check to printoptions See issue #18254 --- numpy/core/arrayprint.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'numpy/core/arrayprint.py') 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 -- cgit v1.2.1