Mean of Period

What is happening there is that the return value of mean is of the same type of the elements of the input array or a type to which a promotion makes sense.

Since the mean can be fractional, the mean cannot be of type Second (although it works when the mean is an integer:

julia> d = [ Second(2), Second(4) ]
2-element Vector{Second}:
 2 seconds
 4 seconds

julia> mean(d)
3 seconds

That said, there is a inner function in Statistics which is _mean and receives a function that will allow you to promote “by hand” the result to float:

julia> Statistics._mean(Dates.value,[ Second(1), Second(2) ])
1.5

The problem, thus, is to decide to what that result should be promoted. A specific method of mean could be implemented for that if it turns out to be used, but the workarounds are fairly quick, so I am not sure if it would be worth the case.

1 Like