Skip to content

Commit

Permalink
Remove type parameters in DataFrameJoiner (#2503)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins committed Oct 29, 2020
1 parent e160eb7 commit f4db95f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
18 changes: 7 additions & 11 deletions src/abstractdataframe/join.jl
Expand Up @@ -10,16 +10,16 @@ const OnType = Union{SymbolOrString, NTuple{2,Symbol}, Pair{Symbol,Symbol},
Pair{<:AbstractString, <:AbstractString}}

# helper structure for DataFrames joining
struct DataFrameJoiner{DF1<:AbstractDataFrame, DF2<:AbstractDataFrame}
dfl::DF1
dfr::DF2
dfl_on::DF1
dfr_on::DF2
struct DataFrameJoiner
dfl::AbstractDataFrame
dfr::AbstractDataFrame
dfl_on::AbstractDataFrame
dfr_on::AbstractDataFrame
left_on::Vector{Symbol}
right_on::Vector{Symbol}

function DataFrameJoiner{DF1, DF2}(dfl::DF1, dfr::DF2,
on::Union{<:OnType, AbstractVector}) where {DF1, DF2}
function DataFrameJoiner(dfl::AbstractDataFrame, dfr::AbstractDataFrame,
on::Union{<:OnType, AbstractVector})
on_cols = isa(on, AbstractVector) ? on : [on]
left_on = Symbol[]
right_on = Symbol[]
Expand All @@ -45,10 +45,6 @@ struct DataFrameJoiner{DF1<:AbstractDataFrame, DF2<:AbstractDataFrame}
end
end

DataFrameJoiner(dfl::DF1, dfr::DF2, on::Union{<:OnType, AbstractVector}) where
{DF1<:AbstractDataFrame, DF2<:AbstractDataFrame} =
DataFrameJoiner{DF1,DF2}(dfl, dfr, on)

# helper map between the row indices in original and joined table
struct RowIndexMap
"row indices in the original table"
Expand Down
4 changes: 2 additions & 2 deletions src/dataframerow/utils.jl
Expand Up @@ -345,7 +345,7 @@ end

# Find index of a row in gd that matches given row by content, 0 if not found
function findrow(gd::RowGroupDict,
df::DataFrame,
df::AbstractDataFrame,
gd_cols::Tuple{Vararg{AbstractVector}},
df_cols::Tuple{Vararg{AbstractVector}},
row::Int)
Expand All @@ -370,7 +370,7 @@ end
# Find indices of rows in 'gd' that match given row by content.
# return empty set if no row matches
function findrows(gd::RowGroupDict,
df::DataFrame,
df::AbstractDataFrame,
gd_cols::Tuple{Vararg{AbstractVector}},
df_cols::Tuple{Vararg{AbstractVector}},
row::Int)
Expand Down
11 changes: 11 additions & 0 deletions test/join.jl
Expand Up @@ -887,4 +887,15 @@ end
@test_throws ArgumentError join(df1, df2, on=:id, kind=:inner)
end

@testset "join mixing DataFrame and SubDataFrame" begin
df1 = DataFrame(a=[1, 2, 3], b=[4, 5, 6])
df1_copy = df1[df1.a .> 1, :]
df1_view1 = @view df1[df1.a .> 1, :]
df1_view2 = @view df1[df1.a .> 1, 1:2]
df2 = DataFrame(a=[1, 2, 3], c=[7, 8, 9])
@test innerjoin(df1_copy, df2, on=:a) ==
innerjoin(df1_view1, df2, on=:a) ==
innerjoin(df1_view2, df2, on=:a)
end

end # module

0 comments on commit f4db95f

Please sign in to comment.