JuliaStats / TimeSeries.jl

Time series toolkit for Julia
Other
349 stars 69 forks source link

Why timestamp has to be Vector{<:TimeType} instead of AbstractVector{<:TimeType} #513

Closed AngelPone closed 1 year ago

AngelPone commented 2 years ago

I'm trying to implement a new specialization of TimeArray whose interval between consecutive timestamps is fixed. Then we can save much space to store the all timestamp. But timestamp::Vector{<:TimeType} will convert timestamp to be Vector.

Specifically, I define a type called EqualPeriodDS

julia> struct EqualPeriodDS{U <: TimeType, T <: Period} <: AbstractArray{U, 1}
    period:: T
    start:: U
    length:: Int
end
julia> # other methods for indexing
julia> ds = EqualPeriodDS(Day(1), Date(2020), 10)
julia> ta = TimeArray(ds, 1:100, [:y])
100×1 TimeArray{Int64, 1, Date, UnitRange{Int64}} 2020-01-02 to 2020-04-10
│            │ y     │
├────────────┼───────┤
│ 2020-01-02 │ 1     │
│ 2020-01-03 │ 2     │
│ ⋮          │ ⋮     │
│ 2020-04-09 │ 99    │
│ 2020-04-10 │ 100   │

julia> timestamp(ta)
100-element Vector{Date}: