Skip to content

Commit

Permalink
Improves doc on collapse (#526)
Browse files Browse the repository at this point in the history
* improves doc on collapse

* adds docs
  • Loading branch information
ValentinKaisermayer authored May 6, 2024
1 parent 7bd872c commit fdfe14b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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

0 comments on commit fdfe14b

Please sign in to comment.