-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
display non-compactly arrays with only one column #22981
Conversation
How about making it non-compact whenever the non-compact form would fit in the screen? |
Yes, I planned to work on this, together with fixing some patholigical (in my opinion) cases like |
@@ -1386,7 +1386,10 @@ end | |||
function alignment(io::IO, x::Pair) | |||
s = sprint(0, show, x, env=io) | |||
if has_tight_type(x) # i.e. use "=>" for display | |||
left = length(sprint(0, show, x.first, env=io)) + 2isa(x.first, Pair) # 2 for parens | |||
iocompact = IOContext(io, :compact => get(io, :compact, true)) | |||
left = length(sprint(0, show, x.first, env=iocompact)) |
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.
unrelated, but this env kwarg is completely undocumented...
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.
Yes, I just copy-pasted from above...
Fair enough, this is an improvement. |
CI failures are 2 timeouts. Anyone opposed to this change? |
Sorry for reacting so late, but I'm not a fan of that behavior. "Compact" printing is not (only?) about the amount of spacing used in the string representation, it's mainly about whether type information is printed or not. AFAIK the idea is that when printing elements inside an array, there's no point in repeating the type information for each element. Indeed,
Concretely, the new behavior is annoying for CategoricalArrays. On Julia 0.6, we have this: julia> CategoricalArray(["a", "b"])
2-element CategoricalArrays.CategoricalArray{String,1,UInt32,String,Union{}}:
"a"
"b" But on 0.7: julia> CategoricalArray(["a", "b"])
2-element CategoricalArrays.CategoricalArray{String,1,UInt32,String,Union{}}:
CategoricalArrays.CategoricalValue{String,UInt32} "a"
CategoricalArrays.CategoricalValue{String,UInt32} "b"
I don't see a way to keep a readable array printing on Julia 0.7 without also removing all type information when printing Maybe we need to distinguish several printing attributes, one for the amount of spacing, and one for the type information? But is the presence of one or two spaces really a big deal? That looks negligible compared with the verbosity of printing all type information. |
Since this PR, I also got annoyed by redundant type information which is not satisfying; so I'm still hoping for something better. Thanks for pointing out the definition of |
I was discussing this with @JeffBezanson the other day and had the realization that we've been using the
The former is something you only want to do when you're actually low on space, so not, for example, when printing a single-column array where there's plenty of horizontal space. The latter is something you want to do in concretely-typed array context no matter what. We may want to separate these two senses of compactness into a |
Makes sense. Note that we have the |
This stuff could definitely use a final design pass. The array printing code is very old and crufty. |
This made vectors of numbers print in full precision:
intended? @rfourquet |
Yes this was intended, the idea here being that there is usually enough room to show the elements non-compactly. But as noted in the last few comments, the situation is still unsatisfying and requires some more decisions. Does this particular example bother you? (besides the doctests as you noted on Slack, which I totally forgot about ;-) ) |
In my opinion, it is quite rare to be interested in this many significant digits so it gives a more noisy impression for little benefit, c.f. |
I must say I would tend to agree, and this example was not the motivation for this PR. But in other cases, like printing complex numbers or pairs, it was frustrating to have vector printing try to save space when it was making it less readable unnecessarily. I would volunteer to improve this, but we don't have a clear solution yet... maybe a specific option in |
Could check if the type is an |
That sounds too ad hoc to me. We need a general solution which allows custom types to choose the most appropriate behavior. For example, Adding options to |
How is this argument specific to vectors? This makes it sound like you just want to always print a limited number of digits of numbers, which strikes me as pretty unjulian. Wanting to see all of the digits of numbers in vectors was one of the motivations of this change. There are two issues that do get conflated into the
Both of these should operate through I/O contexts. Maybe |
Oh, I guess |
To me it is not clear if this is a net gain as it is. In some cases it is better, and in some cases it seems worse. My opinion would be to revert this PR and add it back when we have a method to differ between the conflated IO contexts. Do you have any thoughts on this @rfourquet? |
I would prefer not to revert this. What is the case for vertical vector printing context being "compact"? It seems like the entire issue is just that extra significant digits are a hassle sometimes. |
Alright, perhaps implementing something like |
I also would prefer to not revert, as printing compactly unnecessarily is worse in my view than printing too much. For the number of significant digits, I think it's a matter of personal preference, which maybe could indeed be handled via |
@rfourquet Any news? |
I've been carried away, but your ping motivates me to start working again on this. |
Before, the :compact property was conflating 2 concepts: 1) are we low on screen space? 2) can we skip printing individual type information for elements in a collection? Cf. #22981 for context and discussion. Credit to Stefan Karpinski for the formulation of the design implemented here.
Before, the :compact property was conflating 2 concepts: 1) are we low on screen space? 2) can we skip printing individual type information for elements in a collection? Cf. #22981 for context and discussion. Credit to Stefan Karpinski for the formulation of the design implemented here.
Before, the :compact property was conflating 2 concepts: 1) are we low on screen space? 2) can we skip printing individual type information for elements in a collection? Cf. #22981 for context and discussion. Credit to Stefan Karpinski for the formulation of the design implemented here.
Before, the :compact property was conflating 2 concepts: 1) are we low on screen space? 2) can we skip printing individual type information for elements in a collection? Cf. #22981 for context and discussion. Credit to Stefan Karpinski for the formulation of the design implemented here.
Before, the :compact property was conflating 2 concepts: 1) are we low on screen space? 2) can we skip printing individual type information for elements in a collection? Cf. #22981 for context and discussion. Credit to Stefan Karpinski for the formulation of the design implemented here.
Before, the :compact property was conflating 2 concepts: 1) are we low on screen space? 2) can we skip printing individual type information for elements in a collection? Now, :compact controls only 1), while :typeinfo controls 2). Cf. #22981 for context and discussion. Credit to Stefan Karpinski for the formulation of the design implemented here.
Before, the :compact property was conflating 2 concepts: 1) are we low on screen space? 2) can we skip printing individual type information for elements in a collection? Now, :compact controls only 1), while :typeinfo controls 2). Cf. #22981 for context and discussion. Credit to Stefan Karpinski for the formulation of the design implemented here.
Before, the :compact property was conflating 2 concepts: 1) are we low on screen space? 2) can we skip printing individual type information for elements in a collection? Now, :compact controls only 1), while :typeinfo controls 2). Cf. JuliaLang#22981 for context and discussion. Credit to Stefan Karpinski for the formulation of the design implemented here.
When there is only one column, there is almost all the horizontal space to print one element, so this can as well be printed non-compactly.
Together with #22916 and #22899, this allows to print vectors of pairs more similarly to
Dict
:The last difference I would like to see addressed eventually is the alignment of the first elements of the pairs.