Skip to content

Commit

Permalink
Swap adjoint for permutedims in collapse (#397)
Browse files Browse the repository at this point in the history
* Swap adjoint for permutedims in collapse

This allows collapse to be used with types for which adjoint isn't
defined, such as strings.

It also prevents complex numbers from being conjugated, which may have
come as a surprise to users.
  • Loading branch information
bovine3dom authored and iblislin committed Feb 13, 2019
1 parent 4985916 commit 3473522
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/combine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function collapse(ta::TimeArray{T,N,D}, period::Function, timestamp::Function,

if mapped_tstamp != next_mapped_tstamp
push!(collapsed_tstamps, timestamp(_timestamp(ta)[cluster_startrow:i]))
collapsed_values = [collapsed_values; T[value(values(ta)[cluster_startrow:i, j]) for j in 1:ncols]']
collapsed_values = [collapsed_values; T[value(values(ta)[cluster_startrow:i, j]) for j in 1:ncols] |> permutedims]
cluster_startrow = i+1
end #if

Expand All @@ -116,7 +116,7 @@ function collapse(ta::TimeArray{T,N,D}, period::Function, timestamp::Function,
end #for

push!(collapsed_tstamps, timestamp(_timestamp(ta)[cluster_startrow:end]))
collapsed_values = [collapsed_values; T[value(values(ta)[cluster_startrow:end, j]) for j in 1:ncols]']
collapsed_values = [collapsed_values; T[value(values(ta)[cluster_startrow:end, j]) for j in 1:ncols] |> permutedims]

N == 1 && (collapsed_values = vec(collapsed_values))
return TimeArray(collapsed_tstamps, collapsed_values, colnames(ta), meta(ta))
Expand Down
14 changes: 14 additions & 0 deletions test/combine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ end
@test values(collapse(ohlc, month, first))[2, :] == [104.0, 105.0, 100.0, 100.25]
@test timestamp(collapse(ohlc, month, first))[2] == Date(2000,2,1)
end

# https://github.com/JuliaStats/TimeSeries.jl/pull/397
@testset "Array of String" begin
A = string.(Char.(rand(97:97+25, size(cl))))
ts = timestamp(cl)
ta = TimeArray(ts, A)

let
ta = collapse(ta, week, first)

@test values(ta)[2] == A[6]
@test timestamp(ta)[2] == ts[6]
end
end
end


Expand Down

0 comments on commit 3473522

Please sign in to comment.