You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Info "stats" looks horrible (since numpy 1.14) #6962
With numpy 1.14+ much of the formatting got much better, but info('stats') is not one of them:
t = QTable([[1.0, 1.1, 1.2]])
t.info('stats')
<QTable length=3>
name mean std min max
---- ------------------ ------------------- --- ---
col0 1.0999999999999999 0.08164965809277258 1.0 1.2
where before it was
<QTable length=3>
name mean std min max
---- ---- --------------- --- ---
col0 1.1 0.0816496580928 1.0 1.2
Basically, the rounding rules changed. In the doctests, it was a change like in mean that made it look horrible, but in this example one sees it can be bad without too. I think we basically need to set some default format for columns that uses a sensible number of digits.
@taldcroft - the underlying problem is that numpy changed its behaviour for scalars - like Python ones, they now show the number of digits required to identify the value uniquely, instead of going through arrayprint, which has a default precision of 8. This combined with round-off problems in rounding (which, interestingly, statistics.mean() from the standard library does not have...), means the output looks ugly. The same will hold for any column that holds data with minor rounding errors; it is not specific to info('stats').
I think there are two ways around it: either we have a default format (as you suggest; for backwards compatibility, we could make this %.8g, which is the default precision for np.set_printoptions), or we could ensure that by default, we go through arrayprint (which does somewhat the right thing). The advantage of the latter is that the default format can be controlled via set_printoptions, and that, e.g., the view of a table column will look the same as doing column.data. In principle, we can even control this very simply, using a new legacy option to set_printoptions:
In [21]: np.set_printoptions(legacy='1.13')
In [22]: t.info('stats')
<QTable length=3>
name mean std min max
---- ---- --------------- --- ---
col0 1.1 0.0816496580928 1.0 1.2
Though I think it would be better to slightly adjust the printing routine, and use a proper format; we could still let the default format depend on numpy's arrayprint, by letting it calculate it.
Now that we only support numpy versions that have this change (as well as we can change this now in the new LTS more easily than waiting longer along the road when downstream should support multiple things), it would be nice to come up with a solution for this.
Activity
taldcroft commentedon Dec 10, 2017
I suppose something like
'.6g'would work for float columns?mhvk commentedon Dec 10, 2017
@taldcroft - the underlying problem is that numpy changed its behaviour for scalars - like Python ones, they now show the number of digits required to identify the value uniquely, instead of going through
arrayprint, which has a default precision of 8. This combined with round-off problems in rounding (which, interestingly,statistics.mean()from the standard library does not have...), means the output looks ugly. The same will hold for any column that holds data with minor rounding errors; it is not specific toinfo('stats').I think there are two ways around it: either we have a default format (as you suggest; for backwards compatibility, we could make this
%.8g, which is the defaultprecisionfornp.set_printoptions), or we could ensure that by default, we go througharrayprint(which does somewhat the right thing). The advantage of the latter is that the default format can be controlled viaset_printoptions, and that, e.g., the view of a table column will look the same as doingcolumn.data. In principle, we can even control this very simply, using a newlegacyoption toset_printoptions:Though I think it would be better to slightly adjust the printing routine, and use a proper format; we could still let the default format depend on numpy's arrayprint, by letting it calculate it.
pllim commentedon Dec 23, 2017
Since today is supposed to be the ❄️ , I am moving the milestone. FYI.
[-]Info "stats" looks horrible on numpy 1.14rc[/-][+]Info "stats" looks horrible on numpy 1.14[/+][-]Info "stats" looks horrible on numpy 1.14[/-][+]Info "stats" looks horrible (since numpy 1.14)[/+]bsipocz commentedon Sep 26, 2019
Now that we only support numpy versions that have this change (as well as we can change this now in the new LTS more easily than waiting longer along the road when downstream should support multiple things), it would be nice to come up with a solution for this.
eerovaher commentedon Sep 27, 2021
This issue was resolved by #12022, but it wasn't linked before merging so this issue must be closed manually.
mhvk commentedon Sep 27, 2021
Yes, good change! Closing...