diff --git a/.travis.yml b/.travis.yml index a8e9c11c..1d9be013 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,9 @@ os: - linux julia: - - 0.7 - 1.0 - 1.3 + - 1.4 notifications: email: false diff --git a/Project.toml b/Project.toml index a60a18eb..dbef6fda 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "TimeSeries" uuid = "9e3dc215-6440-5c97-bce1-76c03772f85e" authors = ["JuliaStats "] -version = "0.16.2" +version = "0.17.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -14,8 +14,8 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" [compat] RecipesBase = "0.5, 0.7, 0.8" Reexport = "0.1, 0.2" -Tables = "0.1, 0.2" -julia = "0.7, 1" +Tables = "1" +julia = "1" [extras] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" @@ -25,4 +25,4 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["MarketData", "Test", "DataFrames", "CSV", "Random"] +test = ["CSV", "DataFrames", "MarketData", "Random", "Test"] diff --git a/README.md b/README.md index efa4564a..4c7989c1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ TimeSeries.jl ============ [![Build Status](https://travis-ci.org/JuliaStats/TimeSeries.jl.svg?branch=master)](https://travis-ci.org/JuliaStats/TimeSeries.jl) [![Coverage Status](https://codecov.io/gh/JuliaStats/TimeSeries.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaStats/TimeSeries.jl) -[![TimeSeries](http://pkg.julialang.org/badges/TimeSeries_0.6.svg)](http://pkg.julialang.org/?pkg=TimeSeries&ver=0.6) [![Latest Documentation](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaStats.github.io/TimeSeries.jl/dev) [![Stable Documentation](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaStats.github.io/TimeSeries.jl/stable) diff --git a/src/tables.jl b/src/tables.jl index 8b88ae43..b9767767 100644 --- a/src/tables.jl +++ b/src/tables.jl @@ -1,6 +1,5 @@ # JuliaData/Tables.jl integration -# const TimeArrayColIter = Tables.EachColumn{<:TimeArray} module TablesIntegration using ..TimeSeries @@ -17,8 +16,10 @@ end function TableIter(ta::T) where {T<:TimeArray} N, M = size(ta, 1), size(ta, 2) + 1 - S = Tuple(TimeSeries.replace_dupes!([:timestamp; colnames(ta)])) - TableIter{T,S,N,M}(ta) + col′ = TimeSeries.replace_dupes!([:timestamp; colnames(ta)]) + S = Tuple(col′) + # TODO: `colnames = @view(col′[2:end])` doesn't work at this moment + TableIter{T,S,N,M}(TimeArray(ta, colnames = col′[2:end], unchecked = true)) end data(i::TableIter) = getfield(i, :x) @@ -51,7 +52,12 @@ Tables.rowaccess(::Type{<:TimeArray}) = true Tables.rows(ta::TimeArray) = Tables.rows(Tables.columntable(ta)) Tables.columnaccess(::Type{<:TimeArray}) = true Tables.columns(ta::TimeArray) = TableIter(ta) -Tables.eachcolumn(i::TableIter) = i +Tables.columnnames(ta::TimeArray) = Tables.columnnames(TableIter(ta)) +Tables.columnnames(i::TableIter{T, S}) where {T,S} = collect(Symbol, S) +Tables.getcolumn(ta::TimeArray, i::Int) = Tables.getcolumn(TableIter(ta), i) +Tables.getcolumn(ta::TimeArray, nm::Symbol) = Tables.getcolumn(TableIter(ta), nm) +Tables.getcolumn(i::TableIter, n::Int) = i[n] +Tables.getcolumn(i::TableIter, nm::Symbol) = getproperty(i, nm) Tables.schema(ta::AbstractTimeSeries{T,N,D}) where {T,N,D} = Tables.schema(TableIter(ta)) Tables.schema(i::TableIter{T,S}) where {T,S} = Tables.Schema(S, coltypes(data(i))) diff --git a/test/tables.jl b/test/tables.jl index 73e304bc..a0615e3d 100644 --- a/test/tables.jl +++ b/test/tables.jl @@ -16,7 +16,9 @@ using CSV @test Tables.istable(cl) @test Tables.istable(typeof(cl)) @test Tables.rowaccess(cl) + @test Tables.rowaccess(typeof(cl)) @test Tables.columnaccess(cl) + @test Tables.columnaccess(typeof(cl)) sch = Tables.schema(cl) @test sch.names == (:timestamp, :Close) @@ -27,7 +29,9 @@ using CSV @test Tables.istable(ohlc) @test Tables.istable(typeof(ohlc)) @test Tables.rowaccess(ohlc) + @test Tables.rowaccess(typeof(ohlc)) @test Tables.columnaccess(ohlc) + @test Tables.columnaccess(typeof(ohlc)) sch = Tables.schema(ohlc) @test sch.names == (:timestamp, :Open, :High, :Low, :Close) @@ -38,6 +42,12 @@ end @testset "iterator" begin @testset "single column" begin + @test Tables.columnnames(cl) == [:timestamp; colnames(cl)] + @test Tables.getcolumn(cl, 1) == timestamp(cl) + @test Tables.getcolumn(cl, :timestamp) == timestamp(cl) + @test Tables.getcolumn(cl, 2) == values(cl) + @test Tables.getcolumn(cl, :Close) == values(cl) + # column iterator i = Tables.columns(cl) @test size(i) == (length(cl), 2) @@ -50,6 +60,10 @@ end @test timestamp(i) == timestamp(cl) @test colnames(i) == colnames(cl) @test i.Close == values(cl) + @test Tables.getcolumn(i, 1) == timestamp(cl) + @test Tables.getcolumn(i, :timestamp) == timestamp(cl) + @test Tables.getcolumn(i, 2) == values(cl) + @test Tables.getcolumn(i, :Close) == values(cl) @test propertynames(i) == (:timestamp, :Close) @@ -63,6 +77,12 @@ end end @testset "multi column" begin + @test Tables.columnnames(ohlc) == [:timestamp; colnames(ohlc)] + @test Tables.getcolumn(ohlc, 1) == timestamp(ohlc) + @test Tables.getcolumn(ohlc, :timestamp) == timestamp(ohlc) + @test Tables.getcolumn(ohlc, 3) == values(ohlc[:High]) + @test Tables.getcolumn(ohlc, :High) == values(ohlc[:High]) + # column iterator i = Tables.columns(ohlc) @test size(i) == (length(ohlc), 5) @@ -75,6 +95,10 @@ end @test timestamp(i) == timestamp(ohlc) @test colnames(i) == colnames(ohlc) @test i.Open == values(ohlc.Open) + @test Tables.getcolumn(i, 1) == timestamp(ohlc) + @test Tables.getcolumn(i, :timestamp) == timestamp(ohlc) + @test Tables.getcolumn(i, 3) == values(ohlc[:High]) + @test Tables.getcolumn(i, :High) == values(ohlc[:High]) @test propertynames(i) == (:timestamp, :Open, :High, :Low, :Close) @@ -119,6 +143,9 @@ end # @testset "iterator" @test df.High == values(ta.High) @test df.timestamp_1 == values(ta.timestamp) @test df.Close == values(ta.Close) + + # no side effect on column renaming + @test colnames(ta) == [:Open, :High, :timestamp, :Close] end @testset "DataFrame to TimeArray" begin