dysonance / Temporal.jl

Time series implementation for the Julia language focused on efficiency and flexibility
Other
100 stars 25 forks source link

Construct TS from NamedTuple #33

Closed scls19fr closed 5 years ago

scls19fr commented 5 years ago

Hello,

DataFrame from DataFrames.jl can be construct from NamedTuple

julia> using Dates

julia> using DataFrames

julia> data = (time=[DateTime(2018, 11, 21, 12, 0), DateTime(2018, 11, 21, 13, 0)], col1=[10.2, 11.2], col2=[20.2, 21.2])
(time = DateTime[2018-11-21T12:00:00, 2018-11-21T13:00:00], col1 = [10.2, 11.2], col2 = [20.2, 21.2])

julia> DataFrame(data)
2×3 DataFrame
│ Row │ time                │ col1    │ col2    │
│     │ DateTime            │ Float64 │ Float64 │
├─────┼─────────────────────┼─────────┼─────────┤
│ 1   │ 2018-11-21T12:00:00 │ 10.2    │ 20.2    │
│ 2   │ 2018-11-21T13:00:00 │ 11.2    │ 21.2    │

It will be nice if Temporal.TS could also be constructed like this.

julia> using Temporal

julia> TS(data)

maybe passing name of datetime column should be considered (as a Symbol).

julia> TS(data, index=:time)

LibPQ uses this kind of mechanism https://invenia.github.io/LibPQ.jl/latest/index.html

Kind regards

PS : similar to https://github.com/JuliaStats/TimeSeries.jl/issues/394

dysonance commented 5 years ago

@scls19fr Just wanted to let you know I've pushed changes that added a constructor method from a NamedTuple type as you requested as of this commit (version tagged v0.5.6).

I'm going to close this now assuming that this is what you're after. If there's more to be done, go ahead and let me know and I can reopen and make changes.

Cheers and thanks for the feature request.

scls19fr commented 5 years ago

Thanks @dysonance