Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

DataFrames.CategoricalValue not displaying nicely #807

Open
gszep opened this issue Dec 25, 2020 · 10 comments
Open

DataFrames.CategoricalValue not displaying nicely #807

gszep opened this issue Dec 25, 2020 · 10 comments
Assignees
Labels
almost closed other packages Integration with other Julia packages

Comments

@gszep
Copy link

gszep commented Dec 25, 2020

Screenshot from 2020-12-25 11-19-12

@pankgeorg
Copy link
Collaborator

Hey! Happy holidays!
How would you like that to look? any suggestions?

@PaulToronto
Copy link

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.
df

@gszep
Copy link
Author

gszep commented Dec 29, 2020

Happy holidays to you too! 😄 it would be nice to only show the string value without the type information and without quotations

@rleyvasal
Copy link

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).
JupyterCategoricaltype

By comparison, R Studio also displays the type under the variable name ( for factor and for integer) - without quotes
DisplayCategoricalVariables

@greimel
Copy link
Contributor

greimel commented Jan 1, 2021

Here is a fix,

Base.show(io::IO, ::MIME"text/html", x::CategoricalArrays.CategoricalValue) = print(io, get(x))

before:
image

after:

image

Note, that this matches how CategoricalArrays are shown in the REPL.

image

I wonder if Pluto somehow interferes with the show method defined in CategoricalArrays?

cc @nalimilan

@nalimilan
Copy link

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.

@fonsp
Copy link
Owner

fonsp commented Jan 5, 2021

I proposed a fix: JuliaData/CategoricalArrays.jl#318 .

@fonsp fonsp added almost closed other packages Integration with other Julia packages and removed almost closed labels Jan 5, 2021
@fonsp
Copy link
Owner

fonsp commented Jan 5, 2021

@nalimilan Any suggestions?

@nalimilan
Copy link

I made a detailed proposal above.

@jerlich
Copy link

jerlich commented Feb 6, 2021

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
almost closed other packages Integration with other Julia packages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants