Is it possible to make conditional changes in a TimeArray (TimeSeries) object entries?

Here is a TimeArray object ta as

using TimeSeries

dt = [Date("2011-12-07"), Date("2012-04-06"), Date("2012-07-07")]
par1 = [11, 12, 14]
par2 = [21, 22, 24]

ta = TimeArray((dt = dt, par1 = par1, par2 = par2), timestamp = :dt)
ta
│            │ par1  │ par2  │
├────────────┼───────┼───────┤
│ 2011-12-07 │ 11    │ 21    │
│ 2012-04-06 │ 12    │ 22    │
│ 2012-07-07 │ 14    │ 24    │

In timestamp column, there are 2 Sundays and 1 Saturday here. If I try to change the entry 12 for Saturday in par1 column to 112:

julia> values(ta[day.(timestamp(ta)) .== Sat])[1, 1]
12
julia> values(ta[day.(timestamp(ta)) .== Sat])[1, 1] = 112
112

It does not change the entry in ta. ta remains same:

julia> ta
│            │ par1  │ par2  │
├────────────┼───────┼───────┤
│ 2011-12-07 │ 11    │ 21    │
│ 2012-04-06 │ 12    │ 22    │
│ 2012-07-07 │ 14    │ 24    │

Is there a way to perform any operation to do conditional changes in TimeArray entries?

The problem is that ta[day.(timestamp(ta)) .== Sat] creates new TimeArray object, which is a copy of the original. That is why changes in this object is not reflected in the original ta. There is an old issue, probably when it is resolved you will be able syntax shown in your example.

Currently, you can do something like this

julia> @view(values(ta)[day.(timestamp(ta)) .== Sat, :])[1, 1] = 112;
julia> ta
3×2 TimeArray{Int64, 2, Date, Matrix{Int64}} 2011-12-07 to 2012-07-07
│            │ par1  │ par2  │
├────────────┼───────┼───────┤
│ 2011-12-07 │ 11    │ 21    │
│ 2012-04-06 │ 112   │ 22    │
│ 2012-07-07 │ 14    │ 24    │
1 Like

@Skoffer Thank you for this info. :slight_smile: