DataArrays.jl
DataArrays.jl copied to clipboard
Weighted mean broken for matrices
I am on julia 0.6. Currently the following results in a stack overflow:
x = @data [1.0 2.0 3.0]
w = Weights(rand(3))
mean(x,w,skipna=true)
because this code https://github.com/JuliaStats/DataArrays.jl/blob/8b9e89617ca3539440a9a1b2fc75fc44f86ec850/src/reduce.jl#L178-L185
seems to assume that both the DataArray and the weight vector are of the same shape. However, it does not seem possible to create a Weights Vector with some shape information.
I would be happy to provide a PR with a fix, but wanted to ask before if this behavior is intended in some way...
Thanks for the report. It seems logical to expect that the array and its weights have the same shape; else the correspondence between an element and its weight wouldn't be clear. The error message could be improved, though, and weights should probably accept any kind of array, not just vectors (they have recently been renamed from WeightsVec to Weights). Can you file an issue/PR against StatsBase?