Skip to content

Commit

Permalink
Merge ccd30da into 902e131
Browse files Browse the repository at this point in the history
  • Loading branch information
cjprybol committed Oct 22, 2017
2 parents 902e131 + ccd30da commit 0f0c468
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/abstractdataframe/join.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ function compose_joined_table(joiner::DataFrameJoiner, kind::Symbol,
for (i, col) in enumerate(columns(joiner.dfl))
cols[i] = _similar(col, nrow)
fillcolumn!(cols[i], col, all_orig_left_ixs)
isa(col, CategoricalArray) && levels!(cols[i], levels(col))
end
for (i, col) in enumerate(columns(dfr_noon))
cols[i+ncleft] = _similar(col, nrow)
fillcolumn!(cols[i+ncleft], col, all_orig_right_ixs)
permute!(cols[i+ncleft], right_perm)
isa(col, CategoricalArray) && levels!(cols[i+ncleft], levels(col))
end
res = DataFrame(cols, vcat(names(joiner.dfl), names(dfr_noon)))

Expand Down
12 changes: 12 additions & 0 deletions test/join.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,16 @@ module TestJoin
@test all(isa.(o(on).columns,
[CategoricalVector{Union{T, Null}} for T in (Int, Float64)]))
end

@testset "maintain Categorical levels ordering on join" begin
A = DataFrame(a = [1,2,3], b = ["a", "b", "c"]);
B = DataFrame(b = ["a", "b", "c"], c = levels!(categorical(["a", "b", "b"]), ["b", "a"]));
@test levels(join(A, B, on=:b)[:c]) == ["b", "a"]
@test levels(join(B, A, on=:b)[:c]) == ["b", "a"]
@test levels(join(A, B, on=:b, kind=:inner)[:c]) == ["b", "a"]
@test levels(join(A, B, on=:b, kind=:left)[:c]) == ["b", "a"]
@test levels(join(A, B, on=:b, kind=:right)[:c]) == ["b", "a"]
@test levels(join(A, B, on=:b, kind=:outer)[:c]) == ["b", "a"]
@test levels(join(B, A, on=:b, kind = :semi)[:c]) == ["b", "a"]
end
end

0 comments on commit 0f0c468

Please sign in to comment.