diff options
author | Kexuan Sun <me@kianasun.com> | 2019-07-25 11:26:06 -0700 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2019-07-25 11:26:06 -0700 |
commit | feee90d9e14490daa2439eb37c8511555d073f92 (patch) | |
tree | ef2208871d0a6023ba6603fb4c2c57a023ca1307 /numpy | |
parent | 9259a7ff720ebebdd90dbe5469f08ed386de5f1d (diff) | |
download | numpy-feee90d9e14490daa2439eb37c8511555d073f92.tar.gz |
MAINT: Change the type of error raised in set_printoptions (gh-13899)
Previously an incorrect ``threshold`` raised ``ValueError``; it now raises ``TypeError``
for non-numeric types and ``ValueError`` for ``nan`` values.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/arrayprint.py | 6 | ||||
-rw-r--r-- | numpy/core/tests/test_arrayprint.py | 6 |
2 files changed, 7 insertions, 5 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index 108364824..ecd05d3ac 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -89,8 +89,10 @@ def _make_options_dict(precision=None, threshold=None, edgeitems=None, "`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 " + if not isinstance(threshold, numbers.Number): + raise TypeError("threshold must be numeric") + if np.isnan(threshold): + raise ValueError("threshold must be 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 f2b8fdca7..75a794369 100644 --- a/numpy/core/tests/test_arrayprint.py +++ b/numpy/core/tests/test_arrayprint.py @@ -847,9 +847,9 @@ class TestPrintOptions(object): ) 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') + assert_raises(ValueError, np.set_printoptions, threshold=float('nan')) + assert_raises(TypeError, np.set_printoptions, threshold='1') + assert_raises(TypeError, np.set_printoptions, threshold=b'1') def test_unicode_object_array(): import sys |