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

LinearAlgebra.dot fails with Vector{Union{Float, Missing}} #844

Open
Datseris opened this issue May 7, 2021 · 11 comments · May be fixed by JuliaLang/julia#40769
Open

LinearAlgebra.dot fails with Vector{Union{Float, Missing}} #844

Datseris opened this issue May 7, 2021 · 11 comments · May be fixed by JuliaLang/julia#40769
Labels
missing data Base.missing and related functionality

Comments

@Datseris
Copy link

Datseris commented May 7, 2021

MWE:

julia> using LinearAlgebra

julia> x = [5, 6, missing];

julia> w = [1, 2, 3];

julia> dot(x, w)
ERROR: MethodError: no method matching iterate(::Missing)
Closest candidates are:
  iterate(::Union{LinRange, StepRangeLen}) at range.jl:664
  iterate(::Union{LinRange, StepRangeLen}, ::Int64) at range.jl:664
  iterate(::T) where T<:Union{Base.KeySet{var"#s79", var"#s78"} where {var"#s79", var"#s78"<:Dict}, Base.ValueIterator{var"#s77"} where var"#s77"<:Dict} at dict.jl:693
  ...
Stacktrace:
   [1]  internal
     @ LinearAlgebra
   [2] dot(x::Vector{Union{Missing, Int64}}, y::Vector{Int64})
     @ LinearAlgebra C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\generic.jl:916
Use `err` to retrieve the full stack trace.

I would have assumed that the dot should yield missing.

For reference, I came across this using StatsBase.mean(x, weights(w)).

@dkarrasch dkarrasch linked a pull request May 10, 2021 that will close this issue
@pdeffebach
Copy link

Just want to emphasize there is no passmissing solution for this since we call dot recursively. So I think JuliaLang/julia#40769 is the only way forward absent some sort of number-like iteration for missing.

@nalimilan
Copy link
Member

I think that's a bug in StatsBase, which should only use dot for element types known to give the expected result. Actually we already have an almost finished PR to fix this: JuliaStats/StatsBase.jl#658.

@dkarrasch
Copy link
Member

Does that also fix people's need for a missing-norm? I'm fine with closing my PRs.

@nalimilan
Copy link
Member

I don't have a strong opinion about that.

@Datseris
Copy link
Author

Isn't the fact that this issue was inspired by StatsBase a bit irrelevant here? Shouldn't dot([1, 2, missing], [1, 2, 3]) return missing? Not sure why we keep arguing about StatsBase instead of addressing the main point. I've updated the original post to not use StatsBase at all, as it is not necessary to reproduce the issue.

@pdeffebach
Copy link

Sorry to bring this up again, but is there some way to come to a decision on this? Does it get added to triage?

@nalimilan nalimilan added the missing data Base.missing and related functionality label Jun 10, 2021
@nalimilan
Copy link
Member

JuliaLang/julia#40769 is marked for linalg triage.

@juliohm
Copy link

juliohm commented Jul 23, 2023

It would be nice to have this fixed. I am still pirating the dot definition to make it work in applications with missing values.

@nalimilan
Copy link
Member

For some reason JuliaLang/julia#40769 hasn't been discussed by linalg triage despite the label. I'm not even sure what "linalg triage" is. :-)

@juliohm
Copy link

juliohm commented Oct 17, 2024

Below is the workaround (relies on piracy) we've been using since this issue was opened:

import LinearAlgebra: 
(::Missing, ::Missing) = missing

@adienes
Copy link

adienes commented Oct 17, 2024

I am a card-carrying certified Missing Propagations Hater and I sincerely hope that method is never added to LinearAlgebra

@KristofferC KristofferC transferred this issue from JuliaLang/julia Nov 26, 2024
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

Successfully merging a pull request may close this issue.

6 participants