Commit 5c4f19e0 authored by MichelJuillard's avatar MichelJuillard
Browse files

adding methods

parent 296ba95c
......@@ -4,13 +4,19 @@ using CSV
using DataFrames
using Periods
export TimeDataFrame
struct TimeDataFrame
data::DataFrame
continuous::Bool
frequency::Periods.Frequency
frequency::Frequency
end;
function TimeDataFrame(dataframe::AbstractDataFrame, frequency::Periods.Frequency, firstperiod)
TimeDataFrame() = TimeDataFrame(DataFrame(), true, Undated)
TimeDataFrame(frequency::Frequency) = TimeDataFrame(DataFrame(), true, frequency)
function TimeDataFrame(dataframe::AbstractDataFrame, frequency::Frequency, firstperiod)
data = dataframe
continuous = true
data.Periods = [Period(firstperiod + i - 1, 0, Year) for i in 1:dataframe.nrow]
......@@ -24,4 +30,16 @@ function TimeDataFrame(filename::String, frequency::Frequency, firstperiod)
TimeDataFrame(data, true, frequency)
end
# Redefining getproperty breaks tdf.data !
function Base.getproperty(tdf::TimeDataFrame, symbol::Symbol)
data = getfield(tdf, :data)
x = getproperty(data, symbol)
periods = getproperty(data, :periods)
continuous = getfield(tdf, :continuous)
frequency = getfield(tdf, :frequency)
TimeDataFrame(DataFrame(periods = periods, symbol = x ), continuous, frequency)
end
Base.setproperty!(tdf::TimeDataFrame, symbol::Symbol, x::AbstractArray) = setproperty!(getfield(tdf, :data), symbol, x)
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