From f338c5596b5913b2974149981842b4331597aeaa Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 22 Aug 2020 04:41:49 +0000 Subject: [PATCH] Format files using DocumentFormat --- docs/make.jl | 8 +-- src/IterableTables.jl | 8 +-- src/integrations/dataframes.jl | 2 +- src/integrations/generators.jl | 2 +- src/integrations/juliadb.jl | 44 +++++++-------- src/integrations/statsmodels.jl | 6 +- src/integrations/temporal.jl | 38 ++++++------- src/integrations/timeseries.jl | 40 +++++++------- test/runtests.jl | 8 +-- test/test_integration_dataframes.jl | 66 +++++++++++----------- test/test_integration_gadfly.jl | 6 +- test/test_integration_juliadb.jl | 10 ++-- test/test_integration_statsmodels.jl | 8 +-- test/test_integration_temporal.jl | 80 +++++++++++++-------------- test/test_integration_timeseries.jl | 82 ++++++++++++++-------------- 15 files changed, 204 insertions(+), 204 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 95681f1..27e57ab 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,10 +1,10 @@ using Documenter, IterableTables makedocs( - modules = [IterableTables], + modules=[IterableTables], analytics="UA-132838790-1", - sitename = "IterableTables.jl", - pages = [ + sitename="IterableTables.jl", + pages=[ "Introduction" => "index.md", "User Guide" => "userguide.md", "Integration Guide" => "integrationguide.md", @@ -12,5 +12,5 @@ makedocs( ) deploydocs( - repo = "github.com/queryverse/IterableTables.jl.git" + repo="github.com/queryverse/IterableTables.jl.git" ) diff --git a/src/IterableTables.jl b/src/IterableTables.jl index 5b6f34a..91bb387 100644 --- a/src/IterableTables.jl +++ b/src/IterableTables.jl @@ -8,16 +8,16 @@ using DataValues include("integrations/generators.jl") function __init__() - @require DataFrames="a93c6f00-e57d-5684-b7b6-d8193f3e46c0" if !isdefined(DataFrames, :Tables) + @require DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" if !isdefined(DataFrames, :Tables) include("integrations/dataframes.jl") end - @require StatsModels="3eaba693-59b7-5ba5-a881-562e759f1c8d" if !isdefined(StatsModels, :Tables) + @require StatsModels = "3eaba693-59b7-5ba5-a881-562e759f1c8d" if !isdefined(StatsModels, :Tables) include("integrations/statsmodels.jl") end - @require TimeSeries="9e3dc215-6440-5c97-bce1-76c03772f85e" if !isdefined(TimeSeries, :Tables) + @require TimeSeries = "9e3dc215-6440-5c97-bce1-76c03772f85e" if !isdefined(TimeSeries, :Tables) include("integrations/timeseries.jl") end - @require Temporal="a110ec8f-48c8-5d59-8f7e-f91bc4cc0c3d" include("integrations/temporal.jl") + @require Temporal = "a110ec8f-48c8-5d59-8f7e-f91bc4cc0c3d" include("integrations/temporal.jl") end end # module diff --git a/src/integrations/dataframes.jl b/src/integrations/dataframes.jl index 35baebd..ee8dff6 100644 --- a/src/integrations/dataframes.jl +++ b/src/integrations/dataframes.jl @@ -15,7 +15,7 @@ function _DataFrame(x) return DataFrames.DataFrame(cols, names) end -DataFrames.DataFrame(x::AbstractVector{T}) where {T<:NamedTuple} = _DataFrame(x) +DataFrames.DataFrame(x::AbstractVector{T}) where {T <: NamedTuple} = _DataFrame(x) function DataFrames.DataFrame(x) if TableTraits.isiterabletable(x) diff --git a/src/integrations/generators.jl b/src/integrations/generators.jl index aa7b60e..f078fc4 100644 --- a/src/integrations/generators.jl +++ b/src/integrations/generators.jl @@ -1,4 +1,4 @@ -struct GeneratorWithElType{T, S} +struct GeneratorWithElType{T,S} source::S end diff --git a/src/integrations/juliadb.jl b/src/integrations/juliadb.jl index 98ec7d5..8016760 100644 --- a/src/integrations/juliadb.jl +++ b/src/integrations/juliadb.jl @@ -1,39 +1,39 @@ @require JuliaDB begin -using TableTraits -using JuliaDB: DTable -import IndexedTables + using TableTraits + using JuliaDB: DTable + import IndexedTables -TableTraits.isiterable(x::DTable) = true -TableTraits.isiterabletable(x::DTable) = true + TableTraits.isiterable(x::DTable) = true + TableTraits.isiterabletable(x::DTable) = true # TODO Replace with something more efficient -function TableTraits.getiterator{S<:DTable}(source::S) - it = collect(source) - iter = getiterator(it) + function TableTraits.getiterator{S <: DTable}(source::S) + it = collect(source) + iter = getiterator(it) - return iter -end + return iter + end # TODO Replace with something more efficient -function JuliaDB.distribute(source, rowgroups::AbstractArray; idxcols::Union{Void,Vector{Symbol}}=nothing, datacols::Union{Void,Vector{Symbol}}=nothing) - isiterabletable(source) || error() + function JuliaDB.distribute(source, rowgroups::AbstractArray; idxcols::Union{Void,Vector{Symbol}}=nothing, datacols::Union{Void,Vector{Symbol}}=nothing) + isiterabletable(source) || error() - it = IndexedTables.IndexedTable(source, idxcols=idxcols, datacols=datacols) + it = IndexedTables.IndexedTable(source, idxcols=idxcols, datacols=datacols) - dt = JuliaDB.distribute(it, rowgroups) + dt = JuliaDB.distribute(it, rowgroups) - return dt -end + return dt + end # TODO Replace with something more efficient -function JuliaDB.distribute(source, nchunks::Int=nworkers(); idxcols::Union{Void,Vector{Symbol}}=nothing, datacols::Union{Void,Vector{Symbol}}=nothing) - isiterabletable(source) || error() + function JuliaDB.distribute(source, nchunks::Int=nworkers(); idxcols::Union{Void,Vector{Symbol}}=nothing, datacols::Union{Void,Vector{Symbol}}=nothing) + isiterabletable(source) || error() - it = IndexedTables.IndexedTable(source, idxcols=idxcols, datacols=datacols) + it = IndexedTables.IndexedTable(source, idxcols=idxcols, datacols=datacols) - dt = JuliaDB.distribute(it, nchunks) + dt = JuliaDB.distribute(it, nchunks) - return dt -end + return dt + end end diff --git a/src/integrations/statsmodels.jl b/src/integrations/statsmodels.jl index 6067d57..65edba1 100644 --- a/src/integrations/statsmodels.jl +++ b/src/integrations/statsmodels.jl @@ -3,8 +3,8 @@ function StatsModels.ModelFrame(f::StatsModels.Formula, d; kwargs...) StatsModels.ModelFrame(f, DataFrames.DataFrame(d); kwargs...) end -function StatsModels.StatsBase.fit(::Type{T}, f::StatsModels.Formula, d, args...; contrasts::Dict = Dict(), kwargs...) where - T<:Union{ StatsModels.StatsBase.StatisticalModel, StatsModels.StatsBase.RegressionModel} +function StatsModels.StatsBase.fit(::Type{T}, f::StatsModels.Formula, d, args...; contrasts::Dict=Dict(), kwargs...) where + T <: Union{StatsModels.StatsBase.StatisticalModel,StatsModels.StatsBase.RegressionModel} TableTraits.isiterabletable(d) || error() - StatsModels.StatsBase.fit(T, f, DataFrames.DataFrame(d), args...; contrasts = contrasts, kwargs...) + StatsModels.StatsBase.fit(T, f, DataFrames.DataFrame(d), args...; contrasts=contrasts, kwargs...) end diff --git a/src/integrations/temporal.jl b/src/integrations/temporal.jl index ba1a730..4c6d117 100644 --- a/src/integrations/temporal.jl +++ b/src/integrations/temporal.jl @@ -1,14 +1,14 @@ -struct TSIterator{T, S} +struct TSIterator{T,S} source::S end IteratorInterfaceExtensions.isiterable(x::Temporal.TS) = true TableTraits.isiterabletable(x::Temporal.TS) = true -function IteratorInterfaceExtensions.getiterator(ta::S) where {S<:Temporal.TS} +function IteratorInterfaceExtensions.getiterator(ta::S) where {S <: Temporal.TS} etype = eltype(ta.values) - T = NamedTuple{(:Index, ta.fields...), Tuple{eltype(ta.index), fill(etype, length(ta.fields))...}} + T = NamedTuple{(:Index, ta.fields...),Tuple{eltype(ta.index),fill(etype, length(ta.fields))...}} return TSIterator{T,S}(ta) end @@ -31,17 +31,17 @@ Base.eltype(::Type{TSIterator{T,TS}}) where {T,TS} = T # Add timestamp column push!(constructor_call.args[2].args, :(iter.source.index[i])) - for i in 1:fieldcount(T)-1 + for i in 1:fieldcount(T) - 1 push!(constructor_call.args[2].args, :(iter.source.values[i,$i])) end quote - if state>length(iter.source.index) + if state > length(iter.source.index) return nothing else i = state a = $constructor_call - return a, state+1 + return a, state + 1 end end end @@ -55,7 +55,7 @@ function Temporal.TS(x; index_column::Symbol=:Index) et = eltype(iter) - if fieldcount(et)<2 + if fieldcount(et) < 2 error("Need at least two columns") end @@ -63,15 +63,15 @@ function Temporal.TS(x; index_column::Symbol=:Index) timestep_col_index = findfirst(isequal(index_column), names) - if timestep_col_index===nothing + if timestep_col_index === nothing error("No timestamp column found.") end timestep_col_index = something(timestep_col_index) - col_types = [fieldtype(et, i) for i=1:fieldcount(et)] + col_types = [fieldtype(et, i) for i = 1:fieldcount(et)] - data_columns = collect(Iterators.filter(i->i[2][1]!=index_column, enumerate(zip(names, col_types)))) + data_columns = collect(Iterators.filter(i -> i[2][1] != index_column, enumerate(zip(names, col_types)))) orig_data_type = data_columns[1][2][2] @@ -81,14 +81,14 @@ function Temporal.TS(x; index_column::Symbol=:Index) timestep_type = orig_timestep_type <: DataValues.DataValue ? orig_timestep_type.parameters[1] : orig_timestep_type - if any(i->i[2][2]!=orig_data_type, data_columns) + if any(i -> i[2][2] != orig_data_type, data_columns) error("All data columns need to be of the same type.") end - t_column = Vector{timestep_type}(undef,0) - d_array = Vector{Vector{data_type}}(undef,0) + t_column = Vector{timestep_type}(undef, 0) + d_array = Vector{Vector{data_type}}(undef, 0) for i in data_columns - push!(d_array, Vector{data_type}(undef,0)) + push!(d_array, Vector{data_type}(undef, 0)) end for v in iter @@ -99,18 +99,18 @@ function Temporal.TS(x; index_column::Symbol=:Index) end if orig_data_type <: DataValue - for (i,c) in enumerate(data_columns) - push!(d_array[i],get(v[c[1]])) + for (i, c) in enumerate(data_columns) + push!(d_array[i], get(v[c[1]])) end else - for (i,c) in enumerate(data_columns) - push!(d_array[i],v[c[1]]) + for (i, c) in enumerate(data_columns) + push!(d_array[i], v[c[1]]) end end end d_array = hcat(d_array...) - ta = Temporal.TS(d_array, t_column,[i[2][1] for i in data_columns]) + ta = Temporal.TS(d_array, t_column, [i[2][1] for i in data_columns]) return ta end diff --git a/src/integrations/timeseries.jl b/src/integrations/timeseries.jl index 98386b2..5e16c62 100644 --- a/src/integrations/timeseries.jl +++ b/src/integrations/timeseries.jl @@ -1,16 +1,16 @@ -struct TimeArrayIterator{T, S} +struct TimeArrayIterator{T,S} source::S end IteratorInterfaceExtensions.isiterable(x::TimeSeries.TimeArray) = true TableTraits.isiterabletable(x::TimeSeries.TimeArray) = true -function IteratorInterfaceExtensions.getiterator(ta::S) where {S<:TimeSeries.TimeArray} +function IteratorInterfaceExtensions.getiterator(ta::S) where {S <: TimeSeries.TimeArray} etype = eltype(TimeSeries.values(ta)) - T = NamedTuple{(:timestamp, Symbol.(TimeSeries.colnames(ta))...), Tuple{S.parameters[3], fill(etype, length(TimeSeries.colnames(ta)))...}} + T = NamedTuple{(:timestamp, Symbol.(TimeSeries.colnames(ta))...),Tuple{S.parameters[3],fill(etype, length(TimeSeries.colnames(ta)))...}} - return TimeArrayIterator{T, S}(ta) + return TimeArrayIterator{T,S}(ta) end function Base.length(iter::TimeArrayIterator) @@ -31,17 +31,17 @@ Base.eltype(::Type{TimeArrayIterator{T,TS}}) where {T,TS} = T # Add timestamp column push!(constructor_call.args[2].args, :(TimeSeries.timestamp(iter.source)[i])) - for i in 1:fieldcount(T)-1 + for i in 1:fieldcount(T) - 1 push!(constructor_call.args[2].args, :(TimeSeries.values(iter.source)[i,$i])) end quote - if state>length(TimeSeries.timestamp(iter.source)) + if state > length(TimeSeries.timestamp(iter.source)) return nothing else i = state a = $constructor_call - return a, state+1 + return a, state + 1 end end end @@ -55,7 +55,7 @@ function TimeSeries.TimeArray(x; timestamp_column::Symbol=:timestamp) et = eltype(iter) - if fieldcount(et)<2 + if fieldcount(et) < 2 error("Need at least two columns") end @@ -63,15 +63,15 @@ function TimeSeries.TimeArray(x; timestamp_column::Symbol=:timestamp) timestep_col_index = findfirst(isequal(timestamp_column), names) - if timestep_col_index===nothing + if timestep_col_index === nothing error("No timestamp column found.") end timestep_col_index = something(timestep_col_index) - col_types = [fieldtype(et, i) for i=1:fieldcount(et)] + col_types = [fieldtype(et, i) for i = 1:fieldcount(et)] - data_columns = collect(Iterators.filter(i->i[2][1]!=timestamp_column, enumerate(zip(names, col_types)))) + data_columns = collect(Iterators.filter(i -> i[2][1] != timestamp_column, enumerate(zip(names, col_types)))) orig_data_type = data_columns[1][2][2] @@ -81,14 +81,14 @@ function TimeSeries.TimeArray(x; timestamp_column::Symbol=:timestamp) timestep_type = orig_timestep_type <: DataValues.DataValue ? orig_timestep_type.parameters[1] : orig_timestep_type - if any(i->i[2][2]!=orig_data_type, data_columns) + if any(i -> i[2][2] != orig_data_type, data_columns) error("All data columns need to be of the same type.") end - t_column = Vector{timestep_type}(undef,0) - d_array = Vector{Vector{data_type}}(undef,0) + t_column = Vector{timestep_type}(undef, 0) + d_array = Vector{Vector{data_type}}(undef, 0) for i in data_columns - push!(d_array, Vector{data_type}(undef,0)) + push!(d_array, Vector{data_type}(undef, 0)) end for v in iter @@ -99,18 +99,18 @@ function TimeSeries.TimeArray(x; timestamp_column::Symbol=:timestamp) end if orig_data_type <: DataValue - for (i,c) in enumerate(data_columns) - push!(d_array[i],get(v[c[1]])) + for (i, c) in enumerate(data_columns) + push!(d_array[i], get(v[c[1]])) end else - for (i,c) in enumerate(data_columns) - push!(d_array[i],v[c[1]]) + for (i, c) in enumerate(data_columns) + push!(d_array[i], v[c[1]]) end end end d_array = hcat(d_array...) - ta = TimeSeries.TimeArray(t_column,d_array,[i[2][1] for i in data_columns]) + ta = TimeSeries.TimeArray(t_column, d_array, [i[2][1] for i in data_columns]) return ta end diff --git a/test/runtests.jl b/test/runtests.jl index 7324809..d2f7442 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,10 +5,10 @@ end @testset "IterableTables" begin -include("test_integration_dataframes.jl") -include("test_integration_statsmodels.jl") -include("test_integration_timeseries.jl") -include("test_integration_temporal.jl") + include("test_integration_dataframes.jl") + include("test_integration_statsmodels.jl") + include("test_integration_timeseries.jl") + include("test_integration_temporal.jl") # include("test_integration_juliadb.jl") # include("test_integration_gadfly.jl") diff --git a/test/test_integration_dataframes.jl b/test/test_integration_dataframes.jl index e15a1bb..0ee8d94 100644 --- a/test/test_integration_dataframes.jl +++ b/test/test_integration_dataframes.jl @@ -6,48 +6,48 @@ using Test @testset "DataFrames" begin -source_df = DataFrame(a=Union{Int,Missing}[1,2,3], b=Union{Float64,Missing}[1.,2.,3.], c=Union{String,Missing}["A","B","C"]) + source_df = DataFrame(a=Union{Int,Missing}[1,2,3], b=Union{Float64,Missing}[1.,2.,3.], c=Union{String,Missing}["A","B","C"]) -@test IteratorInterfaceExtensions.isiterable(source_df) == true + @test IteratorInterfaceExtensions.isiterable(source_df) == true -as_array = collect(IteratorInterfaceExtensions.getiterator(source_df)) + as_array = collect(IteratorInterfaceExtensions.getiterator(source_df)) -@test length(as_array) == 3 -@test as_array == [(a=DataValue(1),b=DataValue(1.),c=DataValue("A")), - (a=DataValue(2),b=DataValue(2.),c=DataValue("B")), - (a=DataValue(3),b=DataValue(3.),c=DataValue("C"))] + @test length(as_array) == 3 + @test as_array == [(a = DataValue(1), b = DataValue(1.), c = DataValue("A")), + (a = DataValue(2), b = DataValue(2.), c = DataValue("B")), + (a = DataValue(3), b = DataValue(3.), c = DataValue("C"))] -data = [] -push!(data, [1,2,3]) -push!(data, [1.,2.,3.]) -push!(data, ["A","B","C"]) -source_df_non_nullable = DataFrame(data, [:a,:b,:c]) + data = [] + push!(data, [1,2,3]) + push!(data, [1.,2.,3.]) + push!(data, ["A","B","C"]) + source_df_non_nullable = DataFrame(data, [:a,:b,:c]) -non_nullable_as_array = collect(IteratorInterfaceExtensions.getiterator(source_df_non_nullable)) + non_nullable_as_array = collect(IteratorInterfaceExtensions.getiterator(source_df_non_nullable)) -@test length(non_nullable_as_array) == 3 -@test as_array == [(a=1,b=1.,c="A"),(a=2,b=2.,c="B"),(a=3,b=3.,c="C")] + @test length(non_nullable_as_array) == 3 + @test as_array == [(a = 1, b = 1., c = "A"),(a = 2, b = 2., c = "B"),(a = 3, b = 3., c = "C")] -source_array_non_nullable = [(a=1,b=1.,c="A"), (a=2,b=2.,c="B"), (a=3,b=3.,c="C")] -df = DataFrame(source_array_non_nullable) + source_array_non_nullable = [(a = 1, b = 1., c = "A"), (a = 2, b = 2., c = "B"), (a = 3, b = 3., c = "C")] + df = DataFrame(source_array_non_nullable) -@test size(df) == (3,3) -@test isa(df[:a], Array) -@test isa(df[:b], Array) -@test isa(df[:c], Array) -@test df[:a] == [1,2,3] -@test df[:b] == [1.,2.,3.] -@test df[:c] == ["A","B","C"] + @test size(df) == (3, 3) + @test isa(df[:a], Array) + @test isa(df[:b], Array) + @test isa(df[:c], Array) + @test df[:a] == [1,2,3] + @test df[:b] == [1.,2.,3.] + @test df[:c] == ["A","B","C"] -source_array = [(a=DataValue(1),b=DataValue(1.),c=DataValue("A")), (a=DataValue(2),b=DataValue(2.),c=DataValue("B")), (a=DataValue(3),b=DataValue(3.),c=DataValue("C"))] -df = DataFrame(source_array) + source_array = [(a = DataValue(1), b = DataValue(1.), c = DataValue("A")), (a = DataValue(2), b = DataValue(2.), c = DataValue("B")), (a = DataValue(3), b = DataValue(3.), c = DataValue("C"))] + df = DataFrame(source_array) -@test size(df) == (3,3) -@test isa(df[:a], Vector{Union{Int,Missing}}) -@test isa(df[:b], Vector{Union{Float64,Missing}}) -@test isa(df[:c], Vector{Union{String,Missing}}) -@test df[:a] == [1,2,3] -@test df[:b] == [1.,2.,3.] -@test df[:c] == ["A","B","C"] + @test size(df) == (3, 3) + @test isa(df[:a], Vector{Union{Int,Missing}}) + @test isa(df[:b], Vector{Union{Float64,Missing}}) + @test isa(df[:c], Vector{Union{String,Missing}}) + @test df[:a] == [1,2,3] + @test df[:b] == [1.,2.,3.] + @test df[:c] == ["A","B","C"] end diff --git a/test/test_integration_gadfly.jl b/test/test_integration_gadfly.jl index de33a0f..b8aee45 100644 --- a/test/test_integration_gadfly.jl +++ b/test/test_integration_gadfly.jl @@ -6,10 +6,10 @@ using Base.Test @testset "Gadfly" begin -source_dt = DataTable(a=[1,2,3], b=[4,2,6]) + source_dt = DataTable(a=[1,2,3], b=[4,2,6]) -p = Gadfly.plot(source_dt, x=:a, y=:b, Geom.line) + p = Gadfly.plot(source_dt, x=:a, y=:b, Geom.line) -@test isa(p, Gadfly.Plot) + @test isa(p, Gadfly.Plot) end diff --git a/test/test_integration_juliadb.jl b/test/test_integration_juliadb.jl index cac44f3..30bc408 100644 --- a/test/test_integration_juliadb.jl +++ b/test/test_integration_juliadb.jl @@ -7,14 +7,14 @@ using Base.Test @testset "JuliaDB" begin -source_df = DataFrame(a=[1,2,3], b=[4.,5.,6.]) + source_df = DataFrame(a=[1,2,3], b=[4.,5.,6.]) -jdb = distribute(source_df) + jdb = distribute(source_df) -@test isa(jdb, JuliaDB.DTable) + @test isa(jdb, JuliaDB.DTable) -target_df = DataFrame(jdb) + target_df = DataFrame(jdb) -@test source_df == target_df + @test source_df == target_df end diff --git a/test/test_integration_statsmodels.jl b/test/test_integration_statsmodels.jl index a81085f..d883303 100644 --- a/test/test_integration_statsmodels.jl +++ b/test/test_integration_statsmodels.jl @@ -6,12 +6,12 @@ using Test @testset "StatsModels" begin -source_array = [(a=1,b=1.,c="A"), (a=2,b=2.,c="B"), (a=3,b=3.,c="C")] + source_array = [(a = 1, b = 1., c = "A"), (a = 2, b = 2., c = "B"), (a = 3, b = 3., c = "C")] -mf_array = StatsModels.ModelFrame(StatsModels.@formula(a~b), source_array) + mf_array = StatsModels.ModelFrame(StatsModels.@formula(a ~ b), source_array) -@test mf_array isa StatsModels.ModelFrame + @test mf_array isa StatsModels.ModelFrame -x = lm(StatsModels.@formula(a~b), source_array) + x = lm(StatsModels.@formula(a ~ b), source_array) end diff --git a/test/test_integration_temporal.jl b/test/test_integration_temporal.jl index 041de82..b9a3a71 100644 --- a/test/test_integration_temporal.jl +++ b/test/test_integration_temporal.jl @@ -7,45 +7,45 @@ using Test @testset "Temporal" begin -dates = collect(Date(1999,1,1):Day(1):Date(1999,1,3)) - -source_ta1 = TS(collect(1:length(dates)), dates, [:value]) - -@test IteratorInterfaceExtensions.isiterable(source_ta1) == true - -source_it = IteratorInterfaceExtensions.getiterator(source_ta1) - -@test length(source_it) == 3 - -df1 = DataFrame(source_ta1) -@test size(df1) == (3,2) -@test df1[:Index] == dates -@test df1[:value] == [1,2,3] - -source_ta2 = TS(collect(1:length(dates)), dates, :a) -df2 = DataFrame(source_ta2) -@test size(df2) == (3,2) -@test df2[:Index] == dates -@test df2[:a] == [1,2,3] - -source_ta3 = TS(hcat(collect(1:length(dates)), collect(length(dates):-1:1)), dates, [:a, :b]) -df3 = DataFrame(source_ta3) -@test size(df3) == (3,3) -@test df3[:Index] == dates -@test df3[:a] == [1,2,3] -@test df3[:b] == [3,2,1] - -source_ta4 = TS(hcat(collect(1:length(dates)), collect(length(dates):-1:1)), dates, [:a, :b]) -df4 = DataFrame(source_ta4) -@test size(df4) == (3,3) -@test df4[:Index] == dates -@test df4[:a] == [1,2,3] -@test df4[:b] == [3,2,1] - -source_df = DataFrame(a=[4.,5.], Index=[Date(1999,1,1),Date(1999,1,2)], b=[6.,8.]) -ta2 = TS(source_df) -@test size(ta2) == (2,2) -@test ta2.values == [4. 6.;5. 8.] -@test ta2.index == [Date(1999,1,1),Date(1999,1,2)] + dates = collect(Date(1999, 1, 1):Day(1):Date(1999, 1, 3)) + + source_ta1 = TS(collect(1:length(dates)), dates, [:value]) + + @test IteratorInterfaceExtensions.isiterable(source_ta1) == true + + source_it = IteratorInterfaceExtensions.getiterator(source_ta1) + + @test length(source_it) == 3 + + df1 = DataFrame(source_ta1) + @test size(df1) == (3, 2) + @test df1[:Index] == dates + @test df1[:value] == [1,2,3] + + source_ta2 = TS(collect(1:length(dates)), dates, :a) + df2 = DataFrame(source_ta2) + @test size(df2) == (3, 2) + @test df2[:Index] == dates + @test df2[:a] == [1,2,3] + + source_ta3 = TS(hcat(collect(1:length(dates)), collect(length(dates):-1:1)), dates, [:a, :b]) + df3 = DataFrame(source_ta3) + @test size(df3) == (3, 3) + @test df3[:Index] == dates + @test df3[:a] == [1,2,3] + @test df3[:b] == [3,2,1] + + source_ta4 = TS(hcat(collect(1:length(dates)), collect(length(dates):-1:1)), dates, [:a, :b]) + df4 = DataFrame(source_ta4) + @test size(df4) == (3, 3) + @test df4[:Index] == dates + @test df4[:a] == [1,2,3] + @test df4[:b] == [3,2,1] + + source_df = DataFrame(a=[4.,5.], Index=[Date(1999, 1, 1),Date(1999, 1, 2)], b=[6.,8.]) + ta2 = TS(source_df) + @test size(ta2) == (2, 2) + @test ta2.values == [4. 6.;5. 8.] + @test ta2.index == [Date(1999, 1, 1),Date(1999, 1, 2)] end diff --git a/test/test_integration_timeseries.jl b/test/test_integration_timeseries.jl index 6724d32..2d182a4 100644 --- a/test/test_integration_timeseries.jl +++ b/test/test_integration_timeseries.jl @@ -7,46 +7,46 @@ using Test @testset "TimeSeries" begin -dates = collect(Date(1999,1,1):Day(1):Date(1999,1,3)) - -source_ta1 = TimeArray(dates, collect(1:length(dates))) - -@test IteratorInterfaceExtensions.isiterable(source_ta1) == true - -source_it = IteratorInterfaceExtensions.getiterator(source_ta1) - -@test length(source_it) == 3 - -df1 = DataFrame(source_ta1) -@test size(df1) == (3,2) -@test df1[:timestamp] == dates -@test df1[:A] == [1,2,3] - -source_ta2 = TimeArray(dates, collect(1:length(dates)), [:a]) -df2 = DataFrame(source_ta2) -@test size(df2) == (3,2) -@test df2[:timestamp] == dates -@test df2[:a] == [1,2,3] - -source_ta3 = TimeArray(dates, hcat(collect(1:length(dates)), collect(length(dates):-1:1)), [:a, :b]) -df3 = DataFrame(source_ta3) -@test size(df3) == (3,3) -@test df3[:timestamp] == dates -@test df3[:a] == [1,2,3] -@test df3[:b] == [3,2,1] - -source_ta4 = TimeArray(dates, hcat(collect(1:length(dates)), collect(length(dates):-1:1))) -df4 = DataFrame(source_ta4) -@test size(df4) == (3,3) -@test df4[:timestamp] == dates -@test df4[:A] == [1,2,3] -@test df4[:B] == [3,2,1] - -source_df = DataFrame(a=[4.,5.], timestamp=[Date(1999,1,1),Date(1999,1,2)], b=[6.,8.]) -ta2 = TimeArray(source_df, timestamp=:timestamp) -@test length(ta2) == 2 -@test TimeSeries.colnames(ta2) == [:a, :b] -@test TimeSeries.values(ta2) == [4. 6.;5. 8.] -@test TimeSeries.timestamp(ta2) == [Date(1999,1,1),Date(1999,1,2)] + dates = collect(Date(1999, 1, 1):Day(1):Date(1999, 1, 3)) + + source_ta1 = TimeArray(dates, collect(1:length(dates))) + + @test IteratorInterfaceExtensions.isiterable(source_ta1) == true + + source_it = IteratorInterfaceExtensions.getiterator(source_ta1) + + @test length(source_it) == 3 + + df1 = DataFrame(source_ta1) + @test size(df1) == (3, 2) + @test df1[:timestamp] == dates + @test df1[:A] == [1,2,3] + + source_ta2 = TimeArray(dates, collect(1:length(dates)), [:a]) + df2 = DataFrame(source_ta2) + @test size(df2) == (3, 2) + @test df2[:timestamp] == dates + @test df2[:a] == [1,2,3] + + source_ta3 = TimeArray(dates, hcat(collect(1:length(dates)), collect(length(dates):-1:1)), [:a, :b]) + df3 = DataFrame(source_ta3) + @test size(df3) == (3, 3) + @test df3[:timestamp] == dates + @test df3[:a] == [1,2,3] + @test df3[:b] == [3,2,1] + + source_ta4 = TimeArray(dates, hcat(collect(1:length(dates)), collect(length(dates):-1:1))) + df4 = DataFrame(source_ta4) + @test size(df4) == (3, 3) + @test df4[:timestamp] == dates + @test df4[:A] == [1,2,3] + @test df4[:B] == [3,2,1] + + source_df = DataFrame(a=[4.,5.], timestamp=[Date(1999, 1, 1),Date(1999, 1, 2)], b=[6.,8.]) + ta2 = TimeArray(source_df, timestamp=:timestamp) + @test length(ta2) == 2 + @test TimeSeries.colnames(ta2) == [:a, :b] + @test TimeSeries.values(ta2) == [4. 6.;5. 8.] + @test TimeSeries.timestamp(ta2) == [Date(1999, 1, 1),Date(1999, 1, 2)] end