Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sum and mean of skipmissings don't accept the dims kwarg #40081

Open
oxinabox opened this issue Mar 17, 2021 · 1 comment
Open

sum and mean of skipmissings don't accept the dims kwarg #40081

oxinabox opened this issue Mar 17, 2021 · 1 comment
Labels
missing data Base.missing and related functionality

Comments

@oxinabox
Copy link
Contributor

julia> sum(skipmissing([1 2; missing 3]); dims=2)
ERROR: MethodError: no method matching mapfoldl(::typeof(identity), ::typeof(Base.add_sum), ::Base.SkipMissing{Matrix{Union{Missing, Int64}}}; dims=2)
Closest candidates are:
  mapfoldl(::Any, ::Any, ::Any; init) at reduce.jl:162 got unsupported keyword argument "dims"
Stacktrace:
 [1] kwerr(::NamedTuple{(:dims,), Tuple{Int64}}, ::Function, ::Function, ::Function, ::Base.SkipMissing{Matrix{Union{Missing, Int64}}})
   @ Base ./error.jl:157
 [2] mapreduce(f::Function, op::Function, itr::Base.SkipMissing{Matrix{Union{Missing, Int64}}}; kw::Base.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:dims,), Tuple{Int64}}})
   @ Base ./reduce.jl:289
 [3] sum(f::Function, a::Base.SkipMissing{Matrix{Union{Missing, Int64}}}; kw::Base.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:dims,), Tuple{Int64}}})
   @ Base ./reduce.jl:503
 [4] sum(a::Base.SkipMissing{Matrix{Union{Missing, Int64}}}; kw::Base.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:dims,), Tuple{Int64}}})
   @ Base ./reduce.jl:530
 [5] top-level scope
   @ REPL[6]:

Expected output ios [3; 3]

Similar for mean though error is different, it will need the sum case fixed anyway

julia> mean(skipmissing([1 2; missing 3]); dims=2)
ERROR: MethodError: no method matching mean(::Base.SkipMissing{Matrix{Union{Missing, Int64}}}; dims=2)
Closest candidates are:
...
Stacktrace:
[1] top-level scope

Expected output is a matrix [1.5; 3]

Workaround is use eachslice

julia> reshape(mean.(skipmissing.(eachslice([1 2; missing 3], dims=1))), 1, :)
1×2 Matrix{Float64}:
1.5  3.0

Which isn't terrible TBH. especially if you don't care if you get a vector out, then it is just mean.(skipmissing.(eachslice([1 2; missing 3], dims=1)))

There is an old PR relating to this that seems to have gone stale?
#28027

@nalimilan
Copy link
Member

If there's general support for #28027 it shouldn't be too hard to rebase (hopefully).

@nalimilan nalimilan added the missing data Base.missing and related functionality label Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing data Base.missing and related functionality
Projects
None yet
Development

No branches or pull requests

2 participants