Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves doc on collapse #526

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/src/combine.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ using Statistics
collapse(cl, month, last, mean)
```

```@docs
collapse
```

## `vcat`

The `vcat` method is used to concatenate time series: if you have two
Expand Down
23 changes: 21 additions & 2 deletions src/combine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,27 @@ function collapse(ta::TimeArray, period::Function, timestamp::Function,
TimeArray(ts′, val′, colnames(ta), meta(ta))
end

collapse(ta::TimeArray, p::Period, t::Function, v::Function = t; kw...) =
collapse(ta, x -> floor(x, p), t, v; kw...)
"""
$(SIGNATURES)

The `collapse` method allows for compressing data into a larger time frame.

For example, converting daily data into monthly data. When compressing dates, something rational has to be done with the values
that lived in the more granular time frame. To define what happens, a function call is made.

## Arguments:
- `ta::TimeArray`: Original data
- `period::Union{Function,Dates.Period}`: Period or method for determining the period
- `timestamp::Function`: Method that determines which timestamp represents the whole period, e.g. `last`
- `value::Function = timestamp`: Method that should be applied to the data within the period, e.g. `mean`

```julia
collapse(ta, month, last)
collapse(ta, month, last, mean)
```
"""
collapse(ta::TimeArray, period::Period, timestamp::Function, value::Function = timestamp; kw...) =
collapse(ta, x -> floor(x, period), timestamp, value; kw...)

# vcat ######################

Expand Down
Loading