Skip to content

Commit

Permalink
Incorporate fast join into Base.join
Browse files Browse the repository at this point in the history
  • Loading branch information
asinghvi17 committed Mar 15, 2023
1 parent 653e584 commit 3efcf71
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/join.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
joinmap = Dict(
:JoinInner=>DataFrames.innerjoin,
:JoinBoth=>DataFrames.innerjoin,
:JoinOuter=>DataFrames.outerjoin,
:JoinAll=>DataFrames.outerjoin,
:JoinLeft=>DataFrames.leftjoin,
:JoinRight=>DataFrames.rightjoin
:JoinInner => :inner,
:JoinBoth => :inner,
:JoinOuter => :outer,
:JoinAll => :outer,
:JoinLeft => :left,
:JoinRight => :right,
:outerjoin => :outer,
:innerjoin => :inner,
:leftjoin => :left,
:rightjoin => :right,
)

"""
Expand Down Expand Up @@ -71,6 +75,16 @@ where `jointype` must be one of `:JoinInner`, `:JoinBoth`, `:JoinOuter`, `:JoinA
`cbind` is an alias for `join` method.
## Using the `DataFrames` join methods
DataFrames.jl's join methods are battle-tested, and handle quite a few error cases which `TSFrames.join` may not.
In order to use DataFrames' join methods, which are somewhat slower than `TSFrames.join`, you would have to
join the TSFrames' internal DataFrames, then construct a new TSFrame. For `ts1::TSFrame`, `ts2::TSFrame`,
this is how you would construct an outer join:
```julia
TSFrame(DataFrames.outerjoin(ts1.coredata, ts2.coredata; makeunique = true))
```
# Examples
```jldoctest; setup = :(using TSFrames, DataFrames, Dates, Random, Statistics)
julia> using Random;
Expand Down Expand Up @@ -294,9 +308,9 @@ function Base.join(
ts...;
jointype::Symbol=:JoinAll
)
result = joinmap[jointype](ts1.coredata, ts2.coredata, on=:Index, makeunique=true)
result = TSFrames.fast_join(ts1.coredata, ts2.coredata; method = joinmap[method])
for tsf in ts
result = joinmap[jointype](result, tsf.coredata, on=:Index, makeunique=true)
result = TSFrames.fast_join(result, tsf.coredata; method = joinmap[method])
end
return TSFrame(result)
end
Expand Down Expand Up @@ -430,18 +444,6 @@ function fast_join(left::TSFrame, right::TSFrame; method = :outer)

end

function fast_outerjoin(ts1::TSFrame, ts2::TSFrame, others:::TSFrame...)

result = fast_outerjoin(ts1, ts2)

for other in others
result = fast_outerjoin(ts1, ts2)
end

return result

end

# # as of 22-Jan-22, the timer outputs are as follows:
# BenchmarkTools.Trial: 100 samples with 1 evaluation.
# Range (min … max): 61.627 ms … 287.822 ms ┊ GC (min … max): 0.00% … 71.47%
Expand Down

0 comments on commit 3efcf71

Please sign in to comment.