-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
357 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
module Transforms | ||
|
||
using Dates | ||
using Tables | ||
|
||
export LinearCombination, Transform, Power | ||
export HoD, LinearCombination, Transform, Power | ||
export transform, transform! | ||
|
||
include("utils.jl") | ||
include("transformers.jl") | ||
include("linear_combination.jl") | ||
include("power.jl") | ||
include("temporal.jl") | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
HoD <: Transform | ||
Get the hour of day corresponding to the data. | ||
""" | ||
struct HoD <: Transform end | ||
|
||
|
||
_apply(x, ::HoD) = hour.(x) | ||
|
||
function apply(A::AbstractArray, t::HoD; dims=:, inds=:, kwargs...) | ||
if dims === Colon() | ||
if inds === Colon() | ||
return _apply(A, t; kwargs...) | ||
else | ||
return [_apply(A[ind], t; kwargs...) for ind in inds] | ||
end | ||
end | ||
|
||
return [_apply(x[inds], t; kwargs...) for x in eachslice(A, dims=dims)] | ||
end | ||
|
||
function apply(table, t::HoD; cols=nothing, kwargs...) | ||
Tables.istable(table) || throw(MethodError(apply!, (table, t))) | ||
|
||
# Extract a columns iterator that we should be able to use to mutate the data. | ||
# NOTE: Mutation is not guaranteed for all table types, but it avoid copying the data | ||
columntable = Tables.columns(table) | ||
|
||
cnames = cols === nothing ? propertynames(columntable) : cols | ||
return [_apply(getproperty(columntable, cname), t; kwargs...) for cname in cnames] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
using AxisArrays | ||
using AxisKeys | ||
using DataFrames: DataFrame | ||
using Dates | ||
using Test | ||
using TimeZones | ||
using Transforms | ||
using Transforms: _try_copy | ||
using Test | ||
|
||
@testset "Transforms.jl" begin | ||
include("linear_combination.jl") | ||
include("power.jl") | ||
include("temporal.jl") | ||
end |
Oops, something went wrong.