-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
np.set_printoptions(sign='legacy') edge case for 0d array #9804
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
Comments
For the 0d case you are talking about we are still working on two competing PRs, #9139 and #9201. (These were actually the motivation for all the printing changes). However, I think they both change the 0d printing relative to 1.13 close to the way you described. In particular, in 1.13, a typical 0d float array prints as Essentially it boils down to the fact that the inner element of 0d and 1d arrays now prints the same, so we will get: >>> np.array([1e-10]) # unchanged from 1.13 to 1.14 with sign=legacy
array([1.00000000e-10])
>>> np.array(1e-10) # changes in 1.14 to match the 1d behavior
array(1.00000000e-10) |
By the way, I was aware of this, which is why in the release note I said "setting We'll see if we can remove the "mostly". |
Surely those PRs only affect |
Oh that's true, I guess the current output was the plan for repr. Still, maybe we can think of a way of tweaking |
The leading space here looks like a clear bug, but I think the extra digits are a feature. |
Actually, probably an easy way to make the In that case instead of using |
In which case it sounds like @lesteve is not using as new a version of numpy as they claim to be? Either way, I think there are two ways of looking at this:
|
My argument for getting all these changes in is
In any case, I think we are pretty close to having at least a workable solution for doctests. |
@eric-wieser, at first glance, I think we shoud just make a separate PR to adjust the precision in the exp notation. It does seem inconsistent and ugly. Hooray for |
I am pretty sure that I was using a numpy 1.14 dev version after #9139 was fixed, otherwise I would not have been able to use
As a scikit-learn developer I completely understand this ;-). As I said I think we can work around the problem without requiring numpy changes. I just wanted to report the behaviour so that you can decide what to do about it. And answering "tough luck" is certainly an option I would say, if covering all sign='legacy' edge cases is way too costly. It's a bit hard for me to keep track of all the PRs related to numpy array str/repr related work but do feel free to ping me and I can test some changes on the scikit-learn doctests if that's helpful. |
Oh I see the confusion. My output was for |
After #9139 got merged, I tried using
np.set_printoptions(sign='legacy')
to see whether doctests were passing for scikit-learn with numpy > 1.13. I bumped into the following edge case:numpy 1.13
Output:
numpy 1.14.0.dev0
Output:
I was expecting that with
np.set_printoptions(sign='legacy')
, the behaviour would match exactly on numpy 1.13 and numpy 1.14.0.dev0.Note that it only happens if the number in the array is smaller than the
suppress
argument innp.set_printoptions
. There are probably work-arounds we can use for scikit-learn doctests, like usingnp.set_printoptions(sign='legacy', suppress=True)
to ensure the scientific notation is not used.cc @ahaldane @eric-wieser.
The text was updated successfully, but these errors were encountered: