Skip to content
This repository was archived by the owner on May 4, 2019. It is now read-only.
This repository was archived by the owner on May 4, 2019. It is now read-only.

Weighted mean broken for matrices #287

@meggart

Description

@meggart

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

DataArrays.jl/src/reduce.jl

Lines 178 to 185 in 8b9e896

function Base.mean(a::DataArray, w::Weights; skipna::Bool=false)
if skipna
v = a .* w.values
sum(v; skipna=true) / sum(DataArray(w.values, v.na); skipna=true)
else
any(isna, a) ? NA : mean(a.data, w)
end
end

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions