@@ -395,7 +395,7 @@ function fast_join(left::TSFrame, right::TSFrame; method = :outer)
395395
396396 to = Main. to
397397
398- merged_idx, merged_idx_left, merged_idx_right = @timeit to " sort_merge_idx " sort_merge_idx(index(left), index(right), Val(true ), Val(true ))
398+ merged_idx, merged_idx_left, merged_idx_right = sort_merge_idx(index(left), index(right), Val(true ), Val(true ))
399399
400400 merged_length = length(merged_idx)
401401
@@ -404,43 +404,45 @@ function fast_join(left::TSFrame, right::TSFrame; method = :outer)
404404 # and we can go down a faster path of simple concatenation.
405405 # add_missings = !(length(merged_idx) == length(left) == length(right))
406406
407- @timeit to " column disambiguation" begin
408-
409- left_colnames = setdiff(Tables. columnnames(left. coredata), (:Index,))
410- right_colnames = setdiff(Tables. columnnames(right. coredata), (:Index,))
411- left_colidxs = Tables. columnindex.((left. coredata,), left_colnames)
412- right_colidxs = Tables. columnindex.((right. coredata,), right_colnames)
413- disambiguated_right_colnames = deepcopy(right_colnames)
414-
415- # disambiguate col names
416- for (ind, colname) in enumerate(right_colnames)
417- leftind = findfirst(== (colname), left_colnames)
418- isnothing(leftind) || (disambiguated_right_colnames[ind] = Symbol(string(colname)* " _1" ))
419- end
420-
407+ # this machinery disambiguates column names
408+ # It doesn't take too much time, but it would be cleaner to somehow use
409+ # DataFrames' machinery here.
410+ left_colnames = setdiff(Tables. columnnames(left. coredata), (:Index,))
411+ right_colnames = setdiff(Tables. columnnames(right. coredata), (:Index,))
412+ left_colidxs = Tables. columnindex.((left. coredata,), left_colnames)
413+ right_colidxs = Tables. columnindex.((right. coredata,), right_colnames)
414+ disambiguated_right_colnames = deepcopy(right_colnames)
415+
416+ # disambiguate col names
417+ for (ind, colname) in enumerate(right_colnames)
418+ leftind = findfirst(== (colname), left_colnames)
419+ isnothing(leftind) || (disambiguated_right_colnames[ind] = Symbol(string(colname)* " _1" ))
421420 end
422421
423- @timeit to " DataFrame construction" begin
424- result = DataFrame(:Index => merged_idx; makeunique = false , copycols = false )
425- left_coredata = left. coredata
426- right_coredata = right. coredata
427- end
428422
429- @timeit to " column building" for idx in 1 : length(left_colnames)
423+ # Construct the DataFrame
424+ result = DataFrame(:Index => merged_idx; makeunique = false , copycols = false )
425+ left_coredata = left. coredata
426+ right_coredata = right. coredata
427+
428+ # Store the data from the left table in the result
429+ for idx in 1 : length(left_colnames)
430430 col_idx = left_colidxs[idx]
431- contents = @timeit to " column allocation " DataFrames. similar_missing(left. coredata[! , col_idx], merged_length)
432- @timeit to " column population " (@ inbounds contents[merged_idx_left] = left_coredata[! , col_idx])
433- @timeit to " column transfer " ( result[! , left_colnames[idx]] = contents)
431+ contents = DataFrames. similar_missing(left. coredata[! , col_idx], merged_length)
432+ @inbounds contents[merged_idx_left] = left_coredata[! , col_idx]
433+ result[! , left_colnames[idx]] = contents
434434 end
435435
436- @timeit to " column building" for idx in 1 : length(right_colnames)
436+ # Store the data from the right table in the result
437+ for idx in 1 : length(right_colnames)
437438 col_idx = right_colidxs[idx]
438- contents = @timeit to " column allocation" DataFrames. similar_missing(right. coredata[! , col_idx], merged_length)
439- @timeit to " column population" (@inbounds contents[merged_idx_right] = right_coredata[! , col_idx])
440- @timeit to " column transfer" result[! , disambiguated_right_colnames[idx]] = contents
439+ contents = DataFrames. similar_missing(right. coredata[! , col_idx], merged_length)
440+ @inbounds contents[merged_idx_right] = right_coredata[! , col_idx]
441+ # note that column names have to be disambiguated
442+ result[! , disambiguated_right_colnames[idx]] = contents
441443 end
442444
443- return @timeit to " TSFrame construction " TSFrame(result, :Index; issorted = true , copycols = false )
445+ return TSFrame(result, :Index; issorted = true , copycols = false )
444446
445447end
446448
0 commit comments