-
Notifications
You must be signed in to change notification settings - Fork 360
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
remove dependency on CategoricalArrays.jl in legacy show #2427
Conversation
src/abstractdataframe/show.jl
Outdated
# the T is an instance of CategoricalValue from CategoricalArrays.jl | ||
if hasproperty(T, :name) && | ||
nameof(T.name.module) === :CategoricalArrays && | ||
T.name.name === :CategoricalValue |
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.
Do we not care if the T.parameters[1] <: AbstractString
here?
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.
bacause we are replacing the behaviour for CategoricalValue{<:AbstractString}
defined earlier in line https://github.com/JuliaData/DataFrames.jl/pull/2427/files#diff-38a6c4f0cb7743ccc6d4e8470ebdbd11L69. I just want to ensure I am matching functionality 1-2-1 exactly.
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.
LGTM; hacky, but whatever, it does the job. The alternative route is we put something in DataAPI.jl like iscategorical(x)
or something that CategoricalArrays could overload.
I was also thinking about it, but I think it is best for @nalimilan to decide what is best. In particular if we have |
Mmm, this is definitely very hacky... I see two other possibly clearner solutions:
I wonder what the drawbacks of using |
If we are at it I would actually prefer to switch to If we use |
OK - I have switched @rofinn - could you please have a look at it as you use |
TODO. Check what is printed with this PR if you call:
(this is the output from legacy code) |
Stata prints strings in a dataset without quotes but, for clarity, it also uses a different color (red). Maybe that would be useful to do the same. |
@nalimilan: given the discussion with @ronisbr we should merge this PR anyway (we need this to get rid of CategoricalArrays.jl dependency for HTML and LaTeX even if we start using PrettyTables.jl for text/plain) |
src/abstractdataframe/show.jl
Outdated
if T <: CategoricalValue | ||
# This is only type display shortening so we | ||
# are OK with any T whose name starts with Categorical here | ||
if startswith(sT, "Categorical") |
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.
We only need to handle CategoricalValue
, right. so maybe better strictly check for "CategoricalValue"
? Abbreviating other types could be weird.
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.
OK - I have written it when CategoricalString
was present.
src/abstractdataframe/show.jl
Outdated
`truncstring` indicates the approximate number of text characters width to truncate | ||
the output (if it is a non-positive value then no truncation is applied). | ||
""" | ||
function ourshow(io::IO, x::Any, truncstring::Int; styled::Bool=false) | ||
function ourshow(io::IO, x::T, truncstring::Int; styled::Bool=false) where T |
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.
T
isn't used right?
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.
ah - yes; it was earlier, but we ended up not using it. Fixing.
Co-authored-by: Milan Bouchet-Valat <nalimilan@club.fr>
Now I remember why I used |
Thank you! |
Using reflection is the best what could come up with unless there is a solution to https://stackoverflow.com/questions/63860020/how-to-get-a-list-of-modules-imported-by-a-given-module (which seems unlikely - I have checked the source code, and it seems that this part of the functionality is not exposed to Julia code and is only available in C).
The approach is assuming that if something is pretending to be CategoricalArrays.jl we can just treat it in display as if it were CategoricalArrays.jl (and in general such pretending is unlikely).