From 34735227258dd6b99f7ea7d0793793a5cda43fcc Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Wed, 13 Feb 2019 16:28:31 +0000 Subject: [PATCH] Swap adjoint for permutedims in collapse (#397) * 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. --- src/combine.jl | 4 ++-- test/combine.jl | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/combine.jl b/src/combine.jl index 4ee53b6f..51ae1f5a 100644 --- a/src/combine.jl +++ b/src/combine.jl @@ -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 @@ -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)) diff --git a/test/combine.jl b/test/combine.jl index e3b79aa4..63e90f71 100644 --- a/test/combine.jl +++ b/test/combine.jl @@ -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