Mapreduce with multiple arguments

A similar question was asked in “Method of Mapreduce with multiple arguments” but my implementation of the solution offered in this post did not seem to work.

The problem: I have many TimeArrays (created using TimeSeries.jl) that I would like to use the merge function on. merge takes an optional argument called method that I need to set with a single Symbol (this relates to the index on which the TimeArrays are merged). How can I use mapreduce to merge many TimeArrays at once while including this optional parameters?

Here is some example code. I have only included three TimeArrays in the example, but in reality there are thousands, so it is not feasible to simply compose them by hand.

idx1 = [j for j in DateTime(2000,3,1,9):Hour(1):DateTime(2000,3,1,17)]
idx2 = [j for j in DateTime(2000,3,1,8):Hour(1):DateTime(2000,3,1,16)]
idx3 = [j for j in DateTime(2000,3,1,7):Hour(1):DateTime(2000,3,1,15)]

data1 = rand(Normal(1, 0.5), length(idx1))
data2 = rand(Normal(1, 0.5), length(idx2))
data3 = rand(Normal(1, 0.5), length(idx3))

tas = [TimeArray(i, d) for (i, d) in zip([idx1, idx2, idx3], [data1, data2, data3])]

I can easily merge two of the TimeArrays using the optional parameter method with merge(tas[1], tas[2], method=:outer)and I can merge all three of the TimeArrays without the parameter outer using reduce(merge, tas). However, I get a MethodError when I try

mapreduce(x -> merge(x, method=:outer), tas)

I tried to rewrite this based on the post referenced at the top as
mapreduce((x, y) -> merge(x, method=y), zip(tas, :outer))
but got another MethodError. Where am I going wrong?

Welcome!

You likely want:

reduce((x, y) -> merge(x, y, method=:outer), tas)
5 Likes

Wow, yes I do! Thank you so much.