Commit def6552d authored by MichelJuillard's avatar MichelJuillard
Browse files

move periods in first column of DataFrames

parent 723d7350
......@@ -4,7 +4,7 @@ using CSV
using DataFrames
using Periods
export TimeDataFrame
export TimeDataFrame, innerjoin, outerjoin
mutable struct TimeDataFrame
data::DataFrame
......@@ -320,4 +320,34 @@ function Base.size(df::TimeDataFrame, i::Integer)
end
end
function innerjoin(d1::TimeDataFrame, d2::TimeDataFrame)
freq1 = getfield(d1, :frequency)
freq2 = getfield(d2, :frequency)
if freq1 != freq2
error("innerjoin: both TimeDataFrames must have the same frequency")
end
continuous1 = getfield(d1, :continuous)
continuous2 = getfield(d2, :continuous)
data1 = getfield(d1, :data)
data2 = getfield(d2, :data)
periods1 = getfield(d1, :periods)
periods2 = getfield(d2, :periods)
return TimeDataFrame(sort!(DataFrames.innerjoin(data1, data2, on=:Column1),1), intersect(periods1, periods2), true, freq1)
end
function outerjoin(d1::TimeDataFrame, d2::TimeDataFrame)
freq1 = getfield(d1, :frequency)
freq2 = getfield(d2, :frequency)
if freq1 != freq2
error("innerjoin: both TimeDataFrames must have the same frequency")
end
continuous1 = getfield(d1, :continuous)
continuous2 = getfield(d2, :continuous)
data1 = getfield(d1, :data)
data2 = getfield(d2, :data)
periods1 = getfield(d1, :periods)
periods2 = getfield(d2, :periods)
return TimeDataFrame(sort!(DataFrames.outerjoin(data1, data2, on=:Column1),1), union(periods1, periods2), true, freq1)
end
end # module
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment