summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2018-12-04 06:48:26 -0800
committerGitHub <noreply@github.com>2018-12-04 06:48:26 -0800
commitb35892ad072ca00ba60fef225ec38a22c711bdfa (patch)
tree2e9c19ca18c9fa464774b2aba84025ac5a07bc6b /numpy
parent55bbfafed71bbe83e38bbf4050d1a1d0b54fde8e (diff)
parent0f59087af94b4fba61138334bf8f9c375bf1ae55 (diff)
downloadnumpy-b35892ad072ca00ba60fef225ec38a22c711bdfa.tar.gz
Merge pull request #12353 from mattip/check-threshold
BUG: test, fix for threshold='nan'
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/arrayprint.py7
-rw-r--r--numpy/core/tests/test_arrayprint.py4
2 files changed, 10 insertions, 1 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
index 075d75340..6a71de226 100644
--- a/numpy/core/arrayprint.py
+++ b/numpy/core/arrayprint.py
@@ -26,6 +26,7 @@ __docformat__ = 'restructuredtext'
import sys
import functools
+import numbers
if sys.version_info[0] >= 3:
try:
from _thread import get_ident
@@ -86,7 +87,11 @@ 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) or np.isnan(threshold):
+ raise ValueError("threshold must be numeric and non-NAN, try "
+ "sys.maxsize for untruncated representation")
return options
diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py
index 6522c6e8a..7a858d2e2 100644
--- a/numpy/core/tests/test_arrayprint.py
+++ b/numpy/core/tests/test_arrayprint.py
@@ -842,6 +842,10 @@ class TestPrintOptions(object):
[[ 0.]]]])""")
)
+ def test_bad_args(self):
+ assert_raises(ValueError, np.set_printoptions, threshold='nan')
+ assert_raises(ValueError, np.set_printoptions, threshold=u'1')
+ assert_raises(ValueError, np.set_printoptions, threshold=b'1')
def test_unicode_object_array():
import sys