summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorAllan Haldane <allan.haldane@gmail.com>2017-12-29 18:24:19 -0500
committerAllan Haldane <allan.haldane@gmail.com>2018-01-28 19:18:49 -0500
commit652892bf387344db6cd729fd5acbe4ac0c15b69c (patch)
treebd32a4647471982c4db96336fad391a929338e1a /numpy/core
parent2e4cd0d763265908d1143fcb5ca4ba8e3555a333 (diff)
downloadnumpy-652892bf387344db6cd729fd5acbe4ac0c15b69c.tar.gz
BUG: repr of negative zeros sometimes has an extra space
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/arrayprint.py7
-rw-r--r--numpy/core/tests/test_arrayprint.py2
2 files changed, 5 insertions, 4 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
index aad80dd7a..472318098 100644
--- a/numpy/core/arrayprint.py
+++ b/numpy/core/arrayprint.py
@@ -879,8 +879,7 @@ class FloatingFormat(object):
for x in finite_vals)
int_part, frac_part = zip(*(s.split('.') for s in strs))
if self._legacy == '1.13':
- self.pad_left = 1 + max(len(s.lstrip('-').lstrip('+'))
- for s in int_part)
+ self.pad_left = 1 + max(len(s.lstrip('-+')) for s in int_part)
else:
self.pad_left = max(len(s) for s in int_part)
self.pad_right = max(len(s) for s in frac_part)
@@ -896,8 +895,8 @@ class FloatingFormat(object):
if self._legacy != '1.13':
# account for sign = ' ' by adding one to pad_left
- if all(finite_vals >= 0) and self.sign == ' ':
- self.pad_left += 1
+ if self.sign == ' ' and not any(np.signbit(finite_vals)):
+ self.pad_left += 1
# if there are non-finite values, may need to increase pad_left
if data.size != finite_vals.size:
diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py
index 81e74442b..e63801bba 100644
--- a/numpy/core/tests/test_arrayprint.py
+++ b/numpy/core/tests/test_arrayprint.py
@@ -441,6 +441,7 @@ class TestPrintOptions(object):
assert_equal(repr(np.array([0.])), 'array([0.])')
assert_equal(repr(c),
"array([1. +1.j , 1.12345679+1.12345679j])")
+ assert_equal(repr(np.array([0., -0.])), 'array([ 0., -0.])')
np.set_printoptions(sign=' ')
assert_equal(repr(a), 'array([ 0., 1., 2., 3.])')
@@ -448,6 +449,7 @@ class TestPrintOptions(object):
assert_equal(repr(b), 'array([ 1.234e+09])')
assert_equal(repr(c),
"array([ 1. +1.j , 1.12345679+1.12345679j])")
+ assert_equal(repr(np.array([0., -0.])), 'array([ 0., -0.])')
np.set_printoptions(sign='+')
assert_equal(repr(a), 'array([+0., +1., +2., +3.])')