Commit 6295bd85 authored by MichelJuillard's avatar MichelJuillard
Browse files

switch to ExtendedDates, bump version 0.1.3

parent 5ee267e1
......@@ -2,6 +2,7 @@
[[ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
version = "1.1.1"
[[Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
......@@ -9,6 +10,12 @@ uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[CSTParser]]
deps = ["Tokenize"]
git-tree-sha1 = "b2667530e42347b10c10ba6623cfebc09ac5c7b6"
uuid = "00ebfdb7-1f24-5e51-bd34-a7502290713f"
version = "3.2.4"
[[CSV]]
deps = ["Dates", "Mmap", "Parsers", "PooledArrays", "SentinelArrays", "Tables", "Unicode"]
git-tree-sha1 = "6d4242ef4cb1539e7ede8e01a47a32365e0a34cd"
......@@ -21,6 +28,18 @@ git-tree-sha1 = "f713d583d10fc036252fd826feebc6c173c522a8"
uuid = "324d7699-5711-5eae-9e2f-1d82baa6b597"
version = "0.9.5"
[[CodeTracking]]
deps = ["InteractiveUtils", "UUIDs"]
git-tree-sha1 = "9aa8a5ebb6b5bf469a7e0e2b5202cf6f8c291104"
uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
version = "1.0.6"
[[CommonMark]]
deps = ["Crayons", "JSON", "URIs"]
git-tree-sha1 = "393ac9df4eb085c2ab12005fc496dae2e1da344e"
uuid = "a80b9123-70ca-4bc0-993e-6e3bcb318db6"
version = "0.8.3"
[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "ac4132ad78082518ec2037ae5770b6e796f7f956"
......@@ -69,6 +88,16 @@ uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
[[Downloads]]
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
version = "1.4.0"
[[ExtendedDates]]
deps = ["CodeTracking", "Dates", "JuliaFormatter", "Printf", "Revise"]
path = "../ExtendedDates"
uuid = "78f5a1cc-aa73-4dda-b6b2-4d6b1976988f"
version = "0.1.0"
[[FileWatching]]
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
[[Formatting]]
deps = ["Printf"]
......@@ -95,45 +124,73 @@ git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856"
uuid = "82899510-4779-5014-852e-03e436cf321d"
version = "1.0.0"
[[JLLWrappers]]
deps = ["Preferences"]
git-tree-sha1 = "642a199af8b68253517b80bd3bfd17eb4e84df6e"
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
version = "1.3.0"
[[JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "81690084b6198a2e1da36fcfda16eeca9f9f24e4"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.1"
[[JuliaFormatter]]
deps = ["CSTParser", "CommonMark", "DataStructures", "Pkg", "Tokenize"]
git-tree-sha1 = "cf0dbee6a5a30e2aef87f3b54bc3733ca2df2939"
uuid = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
version = "0.16.1"
[[JuliaInterpreter]]
deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"]
git-tree-sha1 = "e273807f38074f033d94207a201e6e827d8417db"
uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
version = "0.8.21"
[[LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
version = "0.6.2"
[[LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
deps = ["LibSSH2_jll", "Libdl", "MbedTLS_jll", "Pkg", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
version = "7.73.0+4"
[[LibGit2]]
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
[[LibSSH2_jll]]
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
deps = ["Artifacts", "JLLWrappers", "Libdl", "MbedTLS_jll", "Pkg"]
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"
version = "1.9.1+2"
[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
[[LinearAlgebra]]
deps = ["Libdl"]
deps = ["Libdl", "libblastrampoline_jll"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
[[LoweredCodeUtils]]
deps = ["JuliaInterpreter"]
git-tree-sha1 = "491a883c4fef1103077a7f648961adbf9c8dd933"
uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b"
version = "2.1.2"
[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
[[MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
version = "2.24.0+2"
[[Missings]]
deps = ["DataAPI"]
......@@ -145,10 +202,13 @@ version = "0.4.5"
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
[[MozillaCACerts_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
version = "2020.7.22"
[[NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
version = "1.2.0"
[[OrderedCollections]]
git-tree-sha1 = "4fa2ba51070ec13fcc7517db714445b4ab986bdf"
......@@ -161,15 +221,10 @@ git-tree-sha1 = "c8abc88faa3f7a3950832ac5d6e690881590d6dc"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "1.1.0"
[[Periods]]
deps = ["Dates", "Test"]
git-tree-sha1 = "846d5f9989d915415e208c1e4e558cb5f5c489db"
uuid = "0c1d1a06-9168-427d-90e3-b4d73349562f"
version = "0.1.0"
[[Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
version = "1.6.0"
[[PooledArrays]]
deps = ["DataAPI", "Future"]
......@@ -177,6 +232,12 @@ git-tree-sha1 = "cde4ce9d6f33219465b55162811d8de8139c0414"
uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
version = "1.2.1"
[[Preferences]]
deps = ["TOML"]
git-tree-sha1 = "00cfd92944ca9c760982747e9a1d0d5d86ab1e5a"
uuid = "21216c6a-2e73-6563-6e65-726566657250"
version = "1.2.2"
[[PrettyTables]]
deps = ["Crayons", "Formatting", "Markdown", "Reexport", "Tables"]
git-tree-sha1 = "574a6b3ea95f04e8757c0280bb9c29f1a5e35138"
......@@ -200,6 +261,18 @@ git-tree-sha1 = "57d8440b0c7d98fc4f889e478e80f268d534c9d5"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "1.0.0"
[[Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "4036a3bd08ac7e968e27c203d45f5fff15020621"
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.1.3"
[[Revise]]
deps = ["CodeTracking", "Distributed", "FileWatching", "JuliaInterpreter", "LibGit2", "LoweredCodeUtils", "OrderedCollections", "Pkg", "REPL", "Requires", "UUIDs", "Unicode"]
git-tree-sha1 = "1947d2d75463bd86d87eaba7265b0721598dd803"
uuid = "295af30f-e4ad-537b-8983-00126c2a3abe"
version = "3.1.19"
[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
......@@ -242,6 +315,7 @@ version = "1.6.0"
[[TOML]]
deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
version = "1.0.0"
[[TableTraits]]
deps = ["IteratorInterfaceExtensions"]
......@@ -258,11 +332,22 @@ version = "1.4.2"
[[Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
version = "1.9.1"
[[Test]]
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[[Tokenize]]
git-tree-sha1 = "0952c9cee34988092d73a5708780b3917166a0dd"
uuid = "0796e94c-ce3b-5d07-9a54-7f471281c624"
version = "0.5.21"
[[URIs]]
git-tree-sha1 = "97bbe755a53fe859669cd907f2d96aee8d2c1355"
uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
version = "1.3.0"
[[UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
......@@ -271,13 +356,21 @@ uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
[[Zlib_jll]]
deps = ["Libdl"]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
version = "1.2.12+1"
[[libblastrampoline_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
version = "3.0.4+0"
[[nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"
version = "1.41.0+1"
[[p7zip_jll]]
deps = ["Artifacts", "Libdl"]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
version = "16.2.1+1"
name = "TimeDataFrames"
uuid = "ff13af16-2f41-468a-a2e1-aff5c43aabf7"
authors = ["michel "]
version = "0.1.2"
version = "0.1.3"
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Periods = "0c1d1a06-9168-427d-90e3-b4d73349562f"
ExtendedDates = "78f5a1cc-aa73-4dda-b6b2-4d6b1976988f"
[compat]
julia = ">= 1.6.3"
......@@ -2,62 +2,63 @@ module TimeDataFrames
using CSV
using DataFrames
using Periods
using ExtendedDates
export TimeDataFrame, innerjoin, outerjoin
mutable struct TimeDataFrame
data::DataFrame
periods::Vector{Period}
periods::AbstractVector{ExtendedDates.SimpleDate}
continuous::Bool
frequency::Frequency
function TimeDataFrame(data::DataFrame,
periods::AbstractVector{T},
continuous::Bool) where T <: ExtendedDates.SimpleDate
new(data, periods, continuous)
end
end;
TimeDataFrame() = TimeDataFrame(DataFrame(), Vector{Period}(), true,
Undated)
TimeDataFrame(frequency::Frequency) = TimeDataFrame(DataFrame(),
Vector{Period}(), true, frequency)
TimeDataFrame() = TimeDataFrame(DataFrame(), Vector{T}(), true) where T <: ExtendedDates.SimpleDate
function TimeDataFrame(dataframe::AbstractDataFrame, frequency::Frequency, firstperiod;
copycols::Bool=true)
periods = [Period(firstperiod + i - 1, frequency) for i in 1:DataFrames.nrow(dataframe)]
TimeDataFrame(DataFrame(dataframe; copycols), periods, true, frequency)
function TimeDataFrame(dataframe::AbstractDataFrame, firstperiod::T;
copycols::Bool=true) where T <: ExtendedDates.SimpleDate
periods = range(firstperiod, length=DataFrames.nrow(dataframe), step = typeof(firstperiod - firstperiod)(1))
TimeDataFrame(DataFrame(dataframe; copycols), periods, true)
end
function TimeDataFrame(filename::String, frequency::Frequency, firstperiod::Integer)
function TimeDataFrame(filename::String, firstperiod::T) where T <: ExtendedDates.SimpleDate
data = DataFrame(CSV.File(filename))
continuous = true
periods = [Period(firstperiod + i - 1, 0, Year) for i in 1:size(data, 1)]
TimeDataFrame(data, periods, true, frequency)
periods = range(firstperiod, size(data, 1))
TimeDataFrame(data, periods, true)
end
TimeDataFrame(frequency::Frequency, firstperiod, pairs::Pair{Symbol,<:Any}...;
makeunique::Bool=false, copycols::Bool=true) =
TimeDataFrame(firstperiod::T, pairs::Pair{Symbol,<:Any}...;
makeunique::Bool=false, copycols::Bool=true) where T <: ExtendedDates.SimpleDate =
TimeDataFrame(DataFrame(pairs; makeunique, copycols),
frequency, firstperiod)
firstperiod)
TimeDataFrame(frequency::Frequency, firstperiod, pairs::Pair{<:AbstractString,<:Any}...;
makeunique::Bool=false, copycols::Bool=true) =
TimeDataFrame(firstperiod::T, pairs::Pair{<:AbstractString,<:Any}...;
makeunique::Bool=false, copycols::Bool=true) where T <: ExtendedDates.SimpleDate =
TimeDataFrame(DataFrame(pairs; makeunique, copycols),
frequency, firstperiod)
firstperiod)
# these two are needed as a workaround Tables.jl dispatch
TimeDataFrame(pairs::AbstractVector{<:Pair}, frequency::Frequency, firstperiod; makeunique::Bool=false,
copycols::Bool=true) =
TimeDataFrame(pairs::AbstractVector{<:Pair}, firstperiod::T; makeunique::Bool=false,
copycols::Bool=true) where T <: ExtendedDates.SimpleDate =
TimeDataFrame(DataFrame(pairs..., makeunique=makeunique, copycols=copycols),
frequency, firstperiod)
firstperiod)
TimeDataFrame(pairs::NTuple{N, Pair}, frequency::Frequency, firstperiod; makeunique::Bool=false,
copycols::Bool=true) where {N} =
TimeDataFrame(pairs::NTuple{N, Pair}, firstperiod::T; makeunique::Bool=false,
copycols::Bool=true) where {N,T <: ExtendedDates.SimpleDate} =
TimeDataFrame(DataFrame(pairs..., makeunique=makeunique, copycols=copycols),
frequency, firstperiod)
firstperiod)
TimeDataFrame(d::AbstractDict, frequency::Frequency, firstperiod; copycols::Bool=true) =
TimeDataFrame(DataFrame(d; copycols), frequency, firstperiod)
TimeDataFrame(d::AbstractDict, firstperiod::T; copycols::Bool=true) where T <: ExtendedDates.SimpleDate =
TimeDataFrame(DataFrame(d; copycols), firstperiod)
#=
TimeDataFrame(frequency::Frequency, firstperiod; kwargs...)
TimeDataFrame(frequency::ExtendedDates.Frequency, firstperiod::ExtendedDates.SimpleDate; kwargs...)
if isempty(kwargs)
TimeDataFrame()
else
......@@ -81,59 +82,58 @@ TimeDataFrame(frequency::Frequency, firstperiod; kwargs...)
end
=#
TimeDataFrame(columns::AbstractVector, cnames::AbstractVector{Symbol}, frequency::Frequency,
firstperiod; makeunique::Bool=false, copycols::Bool=true) =
TimeDataFrame(DataFrame(columns, cnames; makeunique, copycols), frequency, firstperiod)
TimeDataFrame(columns::AbstractVector, cnames::AbstractVector{Symbol},
firstperiod::T; makeunique::Bool=false, copycols::Bool=true) where T <: ExtendedDates.SimpleDate =
TimeDataFrame(DataFrame(columns, cnames; makeunique, copycols), firstperiod)
TimeDataFrame(columns::AbstractVector, cnames::AbstractVector{<:AbstractString}, frequency::Frequency,
firstperiod; makeunique::Bool=false, copycols::Bool=true) =
TimeDataFrame(columns::AbstractVector, cnames::AbstractVector{<:AbstractString},
firstperiod::T; makeunique::Bool=false, copycols::Bool=true) where T <: ExtendedDates.SimpleDate =
TimeDataFrame(DataFrame(columns, Symbol.(cnames), makeunique=makeunique, copycols=copycols),
frequency, firstperiod)
firstperiod)
TimeDataFrame(columns::AbstractVector{<:AbstractVector}, frequency::Frequency, firstperiod,
TimeDataFrame(columns::AbstractVector{<:AbstractVector}, firstperiod::T,
cnames::AbstractVector{Symbol}=gennames(length(columns));
makeunique::Bool=false, copycols::Bool=true) =
makeunique::Bool=false, copycols::Bool=true) where T <: ExtendedDates.SimpleDate =
TimeDataFrame(DataFrame(collect(AbstractVector, columns),
Index(convert(Vector{Symbol}, cnames), makeunique=makeunique),
copycols=copycols), frequency, firstperiod)
copycols=copycols), firstperiod)
TimeDataFrame(columns::AbstractVector{<:AbstractVector},
cnames::AbstractVector{<:AbstractString}, frequency::Frequency, firstperiod;
makeunique::Bool=false, copycols::Bool=true) =
cnames::AbstractVector{<:AbstractString}, firstperiod::T;
makeunique::Bool=false, copycols::Bool=true) where T <: ExtendedDates.SimpleDate =
TimeDataFrame(DataFrame(columns, Symbol.(cnames); makeunique=makeunique, copycols=copycols),
frequency, firstperiod)
firstperiod)
TimeDataFrame(columns::NTuple{N, AbstractVector}, cnames::NTuple{N, Symbol}, frequency::Frequency, firstperiod;
makeunique::Bool=false, copycols::Bool=true) where {N} =
TimeDataFrame(columns::NTuple{N, AbstractVector}, cnames::NTuple{N, Symbol}, firstperiod::T;
makeunique::Bool=false, copycols::Bool=true) where {N, T <: ExtendedDates.SimpleDate} =
TimeDataFrame(DataFrame(collect(AbstractVector, columns), collect(Symbol, cnames),
makeunique=makeunique, copycols=copycols), frequency, firstperiod)
makeunique=makeunique, copycols=copycols), firstperiod)
TimeDataFrame(columns::NTuple{N, AbstractVector}, cnames::NTuple{N, AbstractString}, frequency::Frequency, firstperiod;
makeunique::Bool=false, copycols::Bool=true) where {N} =
TimeDataFrame(DataFrame(columns, Symbol.(cnames); makeunique=makeunique, copycols=copycols), frequency,
TimeDataFrame(columns::NTuple{N, AbstractVector}, cnames::NTuple{N, AbstractString}, firstperiod::T;
makeunique::Bool=false, copycols::Bool=true) where {N, T <: ExtendedDates.SimpleDate} =
TimeDataFrame(DataFrame(columns, Symbol.(cnames); makeunique=makeunique, copycols=copycols),
firstperiod)
TimeDataFrame(columns::NTuple{N, AbstractVector}, frequency::Frequency, firstperiod; copycols::Bool=true) where {N} =
TimeDataFrame(columns::NTuple{N, AbstractVector}, firstperiod::T; copycols::Bool=true) where {N, T <: ExtendedDates.SimpleDate} =
TimeDataFrame(DataFrame(collect(AbstractVector, columns), gennames(length(columns)),
copycols=copycols), frequency, firstperiod)
copycols=copycols), firstperiod)
TimeDataFrame(columns::AbstractMatrix, frequency::Frequency, firstperiod,
cnames::AbstractVector{Symbol} = gennames(size(columns, 2)); makeunique::Bool=false) =
TimeDataFrame(columns::AbstractMatrix, firstperiod::T,
cnames::AbstractVector{Symbol} = gennames(size(columns, 2)); makeunique::Bool=false) where T <: ExtendedDates.SimpleDate =
TimeDataFrame(DataFrame(AbstractVector[columns[:, i] for i in 1:size(columns, 2)], cnames,
makeunique=makeunique, copycols=false), frequency, firstperiod)
makeunique=makeunique, copycols=false), firstperiod)
TimeDataFrame(columns::AbstractMatrix, cnames::AbstractVector{<:AbstractString}, frequency::Frequency, firstperiod;
makeunique::Bool=false) =
TimeDataFrame(DataFrame(columns, Symbol.(cnames); makeunique=makeunique), frequency, firstperiod)
TimeDataFrame(columns::AbstractMatrix, cnames::AbstractVector{<:AbstractString}, firstperiod::T;
makeunique::Bool=false) where T <: ExtendedDates.SimpleDate =
TimeDataFrame(DataFrame(columns, Symbol.(cnames); makeunique=makeunique), firstperiod)
TimeDataFrame(column_eltypes::AbstractVector{T}, cnames::AbstractVector{Symbol},
frequency::Frequency, firstperiod, nrows::Integer=0; makeunique::Bool=false) where T<:Type =
TimeDataFrame(DataFrame(column_eltypes, cnames, nrows; makeunique), frequency, firstperiod)
firstperiod::P, nrows::Integer=0; makeunique::Bool=false) where {T<:Type, P <: ExtendedDates.SimpleDate} =
TimeDataFrame(DataFrame(column_eltypes, cnames, nrows; makeunique), firstperiod)
TimeDataFrame(column_eltypes::AbstractVector{<:Type},
cnames::AbstractVector{<:AbstractString},
frequency::Frequency, firstperiod, nrows::Integer=0; makeunique::Bool=false) =
TimeDataFrame(DataFrame(column_eltypes, Symbol.(cnames), nrows; makeunique=makeunique), frequency,
TimeDataFrame(column_eltypes::AbstractVector{T}, cnames::AbstractVector{S}, firstperiod::P,
nrows::Integer=0; makeunique::Bool=false) where {T <: Type, P <: ExtendedDates.SimpleDate, S <: AbstractString} =
TimeDataFrame(DataFrame(column_eltypes, Symbol.(cnames), nrows; makeunique=makeunique),
firstperiod)
# Redefining getproperty breaks tdf.data !
......@@ -142,10 +142,9 @@ function Base.getproperty(tdf::TimeDataFrame, symbol::Symbol)
x = getproperty(data, symbol)
periods = getfield(tdf, :periods)
continuous = getfield(tdf, :continuous)
frequency = getfield(tdf, :frequency)
df = DataFrame()
df[!, symbol] = x
TimeDataFrame(df, periods, continuous, frequency)
TimeDataFrame(df, periods, continuous)
end
Base.names(tdf::TimeDataFrame) = DataFrames.names(DataFrames.index(getfield(tdf, :data)))
......@@ -156,14 +155,12 @@ function Base.setproperty!(tdf::TimeDataFrame, symbol::Symbol, x::AbstractVector
periods = getfield(tdf, :periods)
data[!, symbol] = x
continuous = getfield(tdf, :continuous)
frequency = getfield(tdf, :frequency)
TimeDataFrame(data, periods, continuous, frequency)
TimeDataFrame(data, periods, continuous)
end
function Base.setproperty!(tdf1::TimeDataFrame, col_ind::Symbol, tdf2::TimeDataFrame)
n1 = nrow(tdf1)
n2 = nrow(tdf2)
frequency2 = getfield(tdf2, :frequency)
continuous2 = getfield(tdf2, :continuous)
data1 = getfield(tdf1, :data)
data2 = getfield(tdf2, :data)
......@@ -171,12 +168,11 @@ function Base.setproperty!(tdf1::TimeDataFrame, col_ind::Symbol, tdf2::TimeDataF
if ncol(tdf1) == 0
insertcols!(data1, 1, col_ind => missings(n2))
else
frequency1 = getfield(tdf1, :frequency)
continuous1 = getfield(tdf1, :continuous)
if frequency1 != frequency2
periods1 = getfield(tdf1, :periods)
if typeof(periods1) != typeof(periods2)
error("The frequency must be the same in both TimeDataFrame")
end
periods1 = getfield(tdf1, :periods)
minperiod = (periods1[1] < periods2[1]) ? periods1[1] : periods2[1]
maxperiod = (periods1[n1] > periods2[n2]) ? periods1[n1] : periods2[n2]
# Missing expanding number of periods in data1 if necessary
......@@ -188,7 +184,6 @@ function Base.setproperty!(tdf1::TimeDataFrame, col_ind::Symbol, tdf2::TimeDataF
setfield!(tdf1, :data, data1)
setfield!(tdf1, :periods, periods2)
setfield!(tdf1, :continuous, continuous2)
setfield!(tdf1, :frequency, frequency2)
end
Base.getindex(df::TimeDataFrame, id1::Integer, id2::Integer) = getindex(getfield(df, :data), id1, id2)
......@@ -250,21 +245,18 @@ function Base.copy(bc::Base.Broadcast.Broadcasted{TimeDataFrameStyle})
bcf = Base.Broadcast.flatten(bc)
first_tdf = true
local periods, continuous, frequency
local periods, continuous
colnames = []
for tdf in bcf.args
if tdf isa TimeDataFrame
if first_tdf
periods = getfield(tdf, :periods)
continuous = getfield(tdf, :continuous)
frequency = getfield(tdf, :frequency)
first_tdf = false
elseif getfield(tdf, :periods) != periods
error("Time data frames don't have the same periods")
elseif getfield(tdf, :continuous) != continuous
error("TimeDataFrames don't have the same continuous status")
elseif getfield(tdf, :frequency) != frequency
error("TimdeDataFrames don't have the same frequency")
end
end
end
......@@ -281,7 +273,7 @@ function Base.copy(bc::Base.Broadcast.Broadcasted{TimeDataFrameStyle})
end
end
nrows = length(axes(bcf)[1])
tdf = TimeDataFrame(DataFrame(), periods, continuous, frequency)
tdf = TimeDataFrame(DataFrame(), periods, continuous)
for i in axes(bcf)[2]
if nrows == 0
col = Any[]
......@@ -321,33 +313,29 @@ function Base.size(df::TimeDataFrame, i::Integer)
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)
if typeof(periods1) != typeof(periods2)
error("innerjoin: both TimeDataFrames must have the same frequency")
end
return TimeDataFrame(sort!(DataFrames.innerjoin(data1, data2, on=:Column1),1), intersect(periods1, periods2), true)
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)
if typeof(periods1) != typeof(periods2)
error("innerjoin: both TimeDataFrames must have the same frequency")
end
return TimeDataFrame(sort!(DataFrames.outerjoin(data1, data2, on=:Column1),1), union(periods1, periods2), true)
end
end # module
Supports Markdown
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