Replace & Fill
Base.replace
— Functionreplace(t_array::TimeArray, old_new::Pair...; [, count]) -> TimeArray
Return a copy of t_array
which has all values of old
replaced by new
in accordance with old_new
pair. If count
is specified, then replace at most count
occurrences in total.
Examples
julia> using Dates
julia> t_array = TimeArray([
TimeTick(DateTime("2024-01-01"), 1.0),
TimeTick(DateTime("2024-01-02"), 2.0),
TimeTick(DateTime("2024-01-03"), 3.0),
]);
julia> replace(t_array, 1.0 => 10.0, 2.0 => -2.0)
3-element TimeArray{DateTime, Float64}:
TimeTick(2024-01-01T00:00:00, 10.0)
TimeTick(2024-01-02T00:00:00, -2.0)
TimeTick(2024-01-03T00:00:00, 3.0)
replace(f::Function, t_array::TimeArray; [, count]) -> TimeArray
Return a new array where each element is the result of function f
applied to elements of t_array
. If count
is specified, then replace at most count
occurrences in total.
Examples
julia> using Dates
julia> t_array = TimeArray([
TimeTick(DateTime("2024-01-01"), 1.0),
TimeTick(DateTime("2024-01-02"), 2.0),
TimeTick(DateTime("2024-01-03"), 3.0),
]);
julia> replace(x -> isodd(x) ? -x : x, t_array)
3-element TimeArray{DateTime, Float64}:
TimeTick(2024-01-01T00:00:00, -1.0)
TimeTick(2024-01-02T00:00:00, 2.0)
TimeTick(2024-01-03T00:00:00, -3.0)
Base.append!
— Functionappend!(t_array::TimeArray, new_ticks::AbstractVector{TimeTick}) -> TimeArray
Add new values from items
to new_ticks
and sorts them by date in ascending order.
Avoid inserting data in small batches, as each call to the append method triggers sorting.
Examples
julia> using Dates
julia> t_array = TimeArray([
TimeTick(DateTime("2024-01-01"), 1.0),
TimeTick(DateTime("2024-01-02"), 2.0),
TimeTick(DateTime("2024-01-03"), 3.0),
]);
julia> new_ticks = [
TimeTick(DateTime("2024-01-01"), 1.0),
TimeTick(DateTime("2024-01-02"), 2.0),
TimeTick(DateTime("2024-01-03"), 3.0),
];
julia> append!(t_array, new_ticks)
6-element TimeArray{DateTime, Float64}:
TimeTick(2024-01-01T00:00:00, 1.0)
TimeTick(2024-01-01T00:00:00, 1.0)
TimeTick(2024-01-02T00:00:00, 2.0)
TimeTick(2024-01-02T00:00:00, 2.0)
TimeTick(2024-01-03T00:00:00, 3.0)
TimeTick(2024-01-03T00:00:00, 3.0)
Base.vcat
— Functionvcat(l_array::TimeArray, r_array::TimeArray) -> TimeArray
Concatenates two TimeArray
objects vertically.
Examples
julia> using Dates
julia> t_array_1 = TimeArray([
TimeTick(DateTime("2024-01-01"), 1.0),
TimeTick(DateTime("2024-01-02"), 2.0),
TimeTick(DateTime("2024-01-03"), 3.0),
]);
julia> t_array_2 = TimeArray([
TimeTick(DateTime("2024-01-04"), 1.0),
TimeTick(DateTime("2024-01-02"), 2.0),
TimeTick(DateTime("2024-01-01"), 3.0),
]);
julia> vcat(t_array_1, t_array_2)
6-element TimeArray{DateTime, Float64}:
TimeTick(2024-01-01T00:00:00, 1.0)
TimeTick(2024-01-01T00:00:00, 3.0)
TimeTick(2024-01-02T00:00:00, 2.0)
TimeTick(2024-01-02T00:00:00, 2.0)
TimeTick(2024-01-03T00:00:00, 3.0)
TimeTick(2024-01-04T00:00:00, 1.0)
Base.cumsum
— Functioncumsum(t_array::TimeArray; kw...) -> TimeArray
Cumulative sum along the TimeTick values.
Examples
julia> using Dates
julia> t_array = TimeArray([
TimeTick(DateTime("2024-01-01"), 1.0),
TimeTick(DateTime("2024-01-02"), 2.0),
TimeTick(DateTime("2024-01-03"), 3.0),
]);
julia> cumsum(t_array)
3-element TimeArray{DateTime, Float64}:
TimeTick(2024-01-01T00:00:00, 1.0)
TimeTick(2024-01-02T00:00:00, 3.0)
TimeTick(2024-01-03T00:00:00, 6.0)
TimeArrays.ta_backward_fill
— Functionta_backward_fill([, pattern::Function], t_array::TimeArray) -> TimeArray
Return an array where elements that match pattern
are replaced by nearest previous non-pattern value in t_array
. By default pattern
is isnan
function.
Examples
julia> using Dates
julia> t_array = TimeArray([
TimeTick(DateTime("2024-01-03"), 1.0),
TimeTick(DateTime("2024-01-07"), NaN),
TimeTick(DateTime("2024-01-09"), NaN),
TimeTick(DateTime("2024-01-10"), 5.0),
]);
julia> ta_backward_fill(t_array)
4-element TimeArray{DateTime, Float64}:
TimeTick(2024-01-03T00:00:00, 1.0)
TimeTick(2024-01-07T00:00:00, 1.0)
TimeTick(2024-01-09T00:00:00, 1.0)
TimeTick(2024-01-10T00:00:00, 5.0)
TimeArrays.ta_forward_fill
— Functionta_forward_fill([, pattern::Function], t_array::TimeArray) -> TimeArray
Return an array where elements that match pattern
are replaced by nearest next non-pattern value in t_array
. By default pattern
is isnan
function.
Examples
julia> using Dates
julia> t_array = TimeArray([
TimeTick(DateTime("2024-01-01"), 2.0),
TimeTick(DateTime("2024-01-03"), NaN),
TimeTick(DateTime("2024-01-04"), NaN),
TimeTick(DateTime("2024-01-08"), 7.0),
]);
julia> ta_forward_fill(t_array)
4-element TimeArray{DateTime, Float64}:
TimeTick(2024-01-01T00:00:00, 2.0)
TimeTick(2024-01-03T00:00:00, 7.0)
TimeTick(2024-01-04T00:00:00, 7.0)
TimeTick(2024-01-08T00:00:00, 7.0)
TimeArrays.ta_linear_fill
— Functionta_linear_fill([, pattern::Function], t_array::TimeArray) -> TimeArray
Return an array where elements that match pattern
are replaced by linear interpolation between nearest not-pattern values in t_array
. By default pattern
is isnan
function.
Examples
julia> using Dates
julia> t_array = TimeArray([
TimeTick(DateTime("2024-01-02"), 2.0),
TimeTick(DateTime("2024-01-04"), NaN),
TimeTick(DateTime("2024-01-06"), NaN),
TimeTick(DateTime("2024-01-08"), 8.0),
]);
julia> ta_linear_fill(t_array)
4-element TimeArray{DateTime, Float64}:
TimeTick(2024-01-02T00:00:00, 2.0)
TimeTick(2024-01-04T00:00:00, 4.0)
TimeTick(2024-01-06T00:00:00, 6.0)
TimeTick(2024-01-08T00:00:00, 8.0)