Skip to content

Commit

Permalink
Avoid modifying input data frames in join when creating indicator (#1434
Browse files Browse the repository at this point in the history
)
  • Loading branch information
nickeubank authored and nalimilan committed Jun 20, 2018
1 parent 14f30ad commit 0a3f832
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/abstractdataframe/join.jl
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ function Base.join(df1::AbstractDataFrame,
indicator_cols[i] *= 'X'
end
end
df1[Symbol(indicator_cols[1])] = trues(nrow(df1))
df2[Symbol(indicator_cols[2])] = trues(nrow(df2))
df1 = hcat(df1, DataFrame(Dict(indicator_cols[1] => trues(nrow(df1)))))
df2 = hcat(df2, DataFrame(Dict(indicator_cols[2] => trues(nrow(df2)))))
end

if kind == :cross
Expand Down
6 changes: 6 additions & 0 deletions test/join.jl
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,14 @@ module TestJoin
Name = ["John Doe", "Jane Doe", "Jane Doe", "Joe Blogs", missing],
Job = ["Lawyer", "Doctor", "Florist", missing, "Farmer"],
_merge = ["both", "both", "both", "left_only", "right_only"])

# Check that input data frame isn't modified (#1434)
pre_join_name = copy(name)
pre_join_job = copy(job)
@test join(name, job, on = :ID, kind = :outer, indicator=:_merge,
makeunique=true) outer_indicator
@test name pre_join_name
@test job pre_join_job

# Works with conflicting names
name2 = DataFrame(ID = [1, 2, 3], Name = ["John Doe", "Jane Doe", "Joe Blogs"],
Expand Down

0 comments on commit 0a3f832

Please sign in to comment.