Open gszep opened 3 years ago
Hey! Happy holidays! How would you like that to look? any suggestions?
I don't like that display either and googling for a solution brought me here. The image below shows what I did for a solution, but I am wondering if there is a better way. I'd also like to get rid of the double quotes.
Happy holidays to you too! :smile: it would be nice to only show the string value without the type information and without quotations
I agree the quotes should not be displayed on CategoricalValue, but the type should still be included in the output. The variable type is very useful specially when merging datasets with different data types.
Julia displays the type under the variable name when listing a table in Jupyter notebooks (This would be the best solution).
By comparison, R Studio also displays the type under the variable name (
Here is a fix,
Base.show(io::IO, ::MIME"text/html", x::CategoricalArrays.CategoricalValue) = print(io, get(x))
before:
after:
Note, that this matches how CategoricalArrays are shown in the REPL.
I wonder if Pluto somehow interferes with the show method defined in CategoricalArrays?
cc @nalimilan
show(::CategoricalValue)
gives exactly what is displayed above, i.e. CategoricalValue{Int64, UInt32} ...
. But this printing isn't supposed to be used when printing arrays or tables. DataFrames uses print
to render the contents of its columns, and arrays use show(IOContext(io, :typeinfo=>eltype(column)), column[i])
, which avoids repeating the type information. It would make sense for Pluto to print the eltype of the column under its name, and then pass typeinfo
when printing like arrays.
~I proposed a fix: https://github.com/JuliaData/CategoricalArrays.jl/pull/318 .~
@nalimilan Any suggestions?
I made a detailed proposal above.
Btw, I accidentally found a workaround. If you display a dataframe interpolated in markdown, it shows as in the repl
begin
df = DataFrame=(a = ["foo", "bar"], b=[1,2])
df.a .= categorical(df.a)
md"""
$(df)
"""
end