-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
Reading that TSFrames.jl aims to provide the convenience of Dataframes.jl, I was wondering if it could be possible to make the following functionality of creating a new column work:
First, we create a DataFrame and a TSFrame:
julia> using DataFrames
julia> using TSFrames
julia> d = Date(2025,1,1):Day(1):Date(2025,1,3)
Date("2025-01-01"):Day(1):Date("2025-01-03")
julia> df = DataFrame(Date=d, Value=1:3)
3×2 DataFrame
Row │ Date Value
│ Date Int64
─────┼───────────────────
1 │ 2025-01-01 1
2 │ 2025-01-02 2
3 │ 2025-01-03 3
julia> ts = TSFrame(1:3, d)
3×1 TSFrame with Date Index
Index x1
Date Int64
───────────────────
2025-01-01 1
2025-01-02 2
2025-01-03 3Now we create a new column within the DataFrame
julia> df[!, :New_column] .= 0.0
3-element Vector{Float64}:
0.0
0.0
0.0
julia> df
3×3 DataFrame
Row │ Date Value New_column
│ Date Int64 Float64
─────┼───────────────────────────────
1 │ 2025-01-01 1 0.0
2 │ 2025-01-02 2 0.0
3 │ 2025-01-03 3 0.0It works fine. We try to do something similar with the TSFrame:
julia> ts[!, :New_column] .= 0.0
ERROR: MethodError: no method matching getindex(::TSFrame, ::typeof(!), ::Symbol)
The function `getindex` exists, but no method is defined for this combination of argument types.
Closest candidates are:
getindex(::TSFrame, ::Colon, ::Union{String, Symbol})
@ TSFrames ~/.julia/packages/TSFrames/OTvKe/src/getindex.jl:479
getindex(::TSFrame, ::Int64, ::Union{String, Symbol})
@ TSFrames ~/.julia/packages/TSFrames/OTvKe/src/getindex.jl:259
getindex(::TSFrame, ::T, ::Union{String, Symbol}) where T<:TimeType
@ TSFrames ~/.julia/packages/TSFrames/OTvKe/src/getindex.jl:268Indeed, somehow as a new user I had the impression that the TSFrame type is just the DataFrame with the special first (index) column. And then I felt tempted to apply the tricks applicable for DataFrames.
Metadata
Metadata
Assignees
Labels
No labels