Skip to content

Commit

Permalink
correct signature of merge for AbstractIndex (#2826)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins authored Jul 31, 2021
1 parent 790d45e commit 2b9f667
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
integers in a small range.
([#2812](https://github.com/JuliaData/DataFrames.jl/pull/2812))

# DataFrames.jl v1.2.2 Patch Release Notes

## Bug fixes

* fix a bug in `crossjoin` if the first argument is `SubDataFrame` and
`makeunique=true`
([#2826](https://github.com/JuliaData/DataFrames.jl/issues/2826))

# DataFrames.jl v1.2.1 Patch Release Notes

## Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DataFrames"
uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
version = "1.2.1"
version = "1.2.2"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
2 changes: 1 addition & 1 deletion src/other/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function Base.merge!(x::Index, y::AbstractIndex; makeunique::Bool=false)
return x
end

Base.merge(x::Index, y::AbstractIndex; makeunique::Bool=false) =
Base.merge(x::AbstractIndex, y::AbstractIndex; makeunique::Bool=false) =
merge!(copy(x), y, makeunique=makeunique)

function Base.delete!(x::Index, idx::Integer)
Expand Down
32 changes: 32 additions & 0 deletions test/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,36 @@ end
@test DataFrames.index(dfv)[[:a, :c]] == [1, 2]
end

@testset "merge" begin
i1 = Index([:a, :b, :c])
si11 = SubIndex(i1, 1:2)
si12 = SubIndex(i1, 2:3)
i2 = Index([:c, :d, :e])
si21 = SubIndex(i2, 1:2)
si22 = SubIndex(i2, 2:3)

@test_throws ArgumentError merge(i1, i2)
@test merge(i1, i2, makeunique=true) isa Index
@test names(merge(i1, i2, makeunique=true)) == ["a", "b", "c", "c_1", "d", "e"]
@test_throws ArgumentError merge(i1, si21)
@test merge(i1, si21, makeunique=true) isa Index
@test names(merge(i1, si21, makeunique=true)) == ["a", "b", "c", "c_1", "d"]
@test merge(i1, si22) isa Index
@test names(merge(i1, si22)) == ["a", "b", "c", "d", "e"]
@test merge(si11, i2) isa Index
@test names(merge(si11, i2)) == ["a", "b", "c", "d", "e"]
@test merge(si11, si22) isa Index
@test names(merge(si11, si22)) == ["a", "b", "d", "e"]
@test_throws ArgumentError merge(si12, si21)
@test merge(si12, si21, makeunique=true) isa Index
@test names(merge(si12, si21, makeunique=true)) == ["b", "c", "c_1", "d"]

df = DataFrame(a=1)
dfv = view(df, 1:1, 1:1)
@test_throws ArgumentError crossjoin(df, df)
@test_throws ArgumentError crossjoin(dfv, dfv)
@test crossjoin(df, df, makeunique=true) == DataFrame(a=1, a_1=1)
@test crossjoin(dfv, dfv, makeunique=true) == DataFrame(a=1, a_1=1)
end

end # module

0 comments on commit 2b9f667

Please sign in to comment.