Skip to content

Feature request: creating new columns as in DataFrames #207

@hurak

Description

@hurak

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 
─────┼───────────────────
   12025-01-01      1
   22025-01-02      2
   32025-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      3

Now 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    
─────┼───────────────────────────────
   12025-01-01      1         0.0
   22025-01-02      2         0.0
   32025-01-03      3         0.0

It 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:268

Indeed, 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions