Skip to content
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

NullableCategoricalArrays constructor and levels ordering #62

Closed
cjprybol opened this issue Mar 18, 2017 · 3 comments · Fixed by #63
Closed

NullableCategoricalArrays constructor and levels ordering #62

cjprybol opened this issue Mar 18, 2017 · 3 comments · Fixed by #63

Comments

@cjprybol
Copy link
Contributor

The constructor for NullableCategoricalArray does not adhere to the ordering of the data when ordering levels.

julia> using CategoricalArrays
WARNING: Method definition ==(Base.Nullable{S}, Base.Nullable{T}) in module Base at nullable.jl:244 overwritten in module NullableArrays at /Users/Cameron/.julia/v0.6/NullableArrays/src/operators.jl:128.

julia> x = levels!(CategoricalArray(["B", "B", "A", "A"]), ["C", "B", "A"])
4-element CategoricalArrays.CategoricalArray{String,1,UInt32}:
 "B"
 "B"
 "A"
 "A"

julia> levels(x)
3-element Array{String,1}:
 "C"
 "B"
 "A"

julia> nullx = NullableCategoricalArray(x)
4-element CategoricalArrays.NullableCategoricalArray{String,1,UInt32}:
 "B"
 "B"
 "A"
 "A"

julia> levels(nullx) # why did the levels change?
3-element Array{String,1}:
 "A"
 "B"
 "C"

julia> nullx = NullableCategoricalArray(x, ordered=true)
4-element CategoricalArrays.NullableCategoricalArray{String,1,UInt32}:
 "B"
 "B"
 "A"
 "A"

julia> levels(nullx) # still reordered even with ordered=true
3-element Array{String,1}:
 "A"
 "B"
 "C"

julia> droplevels!(nullx) # does not reset the order
4-element CategoricalArrays.NullableCategoricalArray{String,1,UInt32}:
 "B"
 "B"
 "A"
 "A"

julia> levels(nullx)
2-element Array{String,1}:
 "A"
 "B"

same for Array{Strings}

julia> y = ["B", "B", "A", "A"]
4-element Array{String,1}:
 "B"
 "B"
 "A"
 "A"

julia> nully = NullableCategoricalArray(y)
4-element CategoricalArrays.NullableCategoricalArray{String,1,UInt32}:
 "B"
 "B"
 "A"
 "A"

julia> levels(nully) # ordering
2-element Array{String,1}:
 "A"
 "B"

julia> nully = NullableCategoricalArray(y, ordered=true)
4-element CategoricalArrays.NullableCategoricalArray{String,1,UInt32}:
 "B"
 "B"
 "A"
 "A"

julia> levels(nully) # ordering
2-element Array{String,1}:
 "A"
 "B"

julia> droplevels!(nully)
4-element CategoricalArrays.NullableCategoricalArray{String,1,UInt32}:
 "B"
 "B"
 "A"
 "A"

julia> levels(nully)
2-element Array{String,1}:
 "A"
 "B"
@nalimilan
Copy link
Member

I have a fix here, the hardest part is writing comprehensive tests to cover all cases.

@cjprybol
Copy link
Contributor Author

Awesome! Looking forward to reviewing the code.

@nalimilan
Copy link
Member

OK, see #63.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants