Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copy function to TimeArray #352

Merged
merged 2 commits into from Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/timearray.jl
@@ -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 =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think our compiler is smart enough, and we do not need return type annotation here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if it is redundant, I prefer to annotate types as much as possible. But I will adapt to the style you prefer. Would you prefer to remove the output type?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'm fine with current.

TimeArray(ta.timestamp, ta.values, ta.colnames, ta.meta)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make it 4-space indented?


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

length(ata::AbstractTimeSeries) = length(ata.timestamp)
Expand Down
14 changes: 14 additions & 0 deletions test/timearray.jl
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