Skip to content

Commit

Permalink
Add copy function to TimeArray
Browse files Browse the repository at this point in the history
  • Loading branch information
Israel Herraiz committed Dec 19, 2017
1 parent 761d19a commit 9bc10f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/timearray.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
###### type definition ##########

import Base: convert, length, show, getindex, start, next, done, isempty, endof,
size, eachindex
import Base: convert, copy, length, show, getindex, start, next, done, isempty,
endof, size, eachindex

abstract type AbstractTimeSeries end

Expand Down Expand Up @@ -56,6 +56,11 @@ convert(::Type{TimeArray{Float64, 2}}, x::TimeArray{Bool, 2}) =
convert(x::TimeArray{Bool, 1}) = convert(TimeArray{Float64, 1}, x::TimeArray{Bool, 1})
convert(x::TimeArray{Bool, 2}) = convert(TimeArray{Float64, 2}, x::TimeArray{Bool, 2})

###### copy ###############

copy(ta::TimeArray)::TimeArray =
TimeArray(ta.timestamp, ta.values, ta.colnames, ta.meta)

###### length ###################

length(ata::AbstractTimeSeries) = length(ata.timestamp)
Expand Down
14 changes: 14 additions & 0 deletions test/timearray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ end
end
end

@testset "copy methods" begin
cop = copy(op)
cohlc = copy(ohlc)
@testset "copy works" begin
@test cop.timestamp == op.timestamp
@test cop.values == op.values
@test cop.colnames == op.colnames
@test cop.meta == op.meta
@test cohlc.timestamp == ohlc.timestamp
@test cohlc.values == ohlc.values
@test cohlc.colnames == ohlc.colnames
@test cohlc.meta == ohlc.meta
end
end

@testset "index by integer works with both 1d and 2d time array" begin
@testset "1d time array" begin
Expand Down

0 comments on commit 9bc10f2

Please sign in to comment.