-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: Fix array printing with precision=0. #8107
Conversation
z = s.rstrip('0') | ||
return precision - len(s) + len(z) | ||
else: | ||
return len(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it just return zero? In the non-zero case there is a decimal point that stops the rstrip so the precision returned is the actual number of digits past the decimal point minus trailing zeros. In the zero case that would always be zero if the decimal point was still there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, definitely, thank you for the careful look.
@@ -129,6 +129,13 @@ def test_basic(self): | |||
np.set_printoptions(precision=4) | |||
assert_equal(repr(x), "array([ 1.5 , 0. , 1.2346])") | |||
|
|||
def test_precision_zero(self): | |||
np.set_printoptions(precision=0) | |||
x = np.array([0, .7, 1.5, -1.5]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need some examples like 100.0
.
Values rounding to zero were formatted with negative precision.
954bf5d
to
65e1e0e
Compare
Changed |
Thanks @wrwrwr . |
Not a particularly significant matter, but trying something as follows:
results in:
This is easily fixed by handling the case of rounding to integers when counting significant digits.
I've also included instances of ties-to-even rounding in the test case, after the docstring for rint(), but maybe that's too specific (IEEE 754 defines more rounding modes).