-
Notifications
You must be signed in to change notification settings - Fork 370
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
join()
doesn't preserve categorical levels order
#1257
Comments
Good catch. I think this happens because we call If we can't find an efficient solution which doesn't rely on Would you be willing to investigate this? I'm pretty swamped at the moment. Cc: @cjprybol |
To me copying the pool into the new array when doing |
That would certainly work, but if somebody passes a |
@cjprybol Do you think we could go back to calling |
Yes, if |
Easiest way to handle this looks to be just checking if the original column is a CategoricalArray, and if so, make sure to copy the levels. julia> A = DataFrame(a = [1,2,3], b = ["a", "b", "c"]);
julia> B = DataFrame(b = ["a", "b", "c"], c = levels!(categorical(["a", "b", "b"]), ["b", "a"]));
julia> levels(B[:c])
2-element Array{String,1}:
"b"
"a"
julia> C = join(A, B, on=:b)
3×3 DataFrames.DataFrame
│ Row │ a │ b │ c │
├─────┼───┼───┼───┤
│ 1 │ 1 │ a │ a │
│ 2 │ 2 │ b │ b │
│ 3 │ 3 │ c │ b │
julia> levels(C[:c])
2-element Array{String,1}:
"b"
"a" I couldn't figure out a good way to use |
Yeah, but that's not a generic solution, so I'd have preferred using |
I don't see the connection between |
Good points. Looking at the code, I rediscovered that If that doesn't work, let's got with a special case for |
@cjprybol Do you think you'll be able to find the time to investigate using |
The text was updated successfully, but these errors were encountered: