Itent of `Base.summary` function

I’m curious, how is summary meant to be used? From the description, I get that summary should parrot the type information and the size of the object, but not the actual data. This seems quite useful, as a complement to dump. How are we expecting people to use summary?

Print to a stream io, or return a string str, giving a brief description of a value. By default returns string(typeof(x)), e.g. Int64. For arrays, returns a string of size and type info, e.g. 10-element Array{Int64,1}.

  julia> summary(zeros(2))
  "2-element Array{Float64,1}"

Specific questions: a) it seems that the summary output is limited to a single line, is this a necessary constraint? b) are the actual lengths of the variables needed, this would make it specific to an instance of an object, and while that’s handy it means you’ve got to peek into the actual object, c) it seems that the actual type is to be included, is this implied/required?

It seems that DataFrame has a summary implementation. However, unlike the summary of a vector, it doesn’t include the types of its elements – but it does include the size of the table.

julia> summary(DataFrame(a=[1,2],b=["A","B"]))
"2×2 DataFrame"

Thank you for any advice/thoughts.

summary is supposed to be one line, for inclusion in output like varinfo() where you just want a brief description of a value. Other than that I don’t think there are any requirements; it can be whatever is an appropriate compact description.

1 Like