You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
zero(Missing) currently fails, as does one(Missing) and oneunit(Missing):
julia>zero(Missing)
ERROR: UndefVarError: T not defined
The error comes from this code in base/missing.jl:
for f in (:(Base.zero), :(Base.one), :(Base.oneunit))
@evalfunction$(f)(::Type{Union{T, Missing}}) where T
T === Any &&throw(MethodError($f, (Any,))) # To prevent StackOverflowError$f(T)
endend
Perhaps zero(::Missing) and one(::Missing) should be missing, since missing + missing == missing and the same for * and those two methods give you the additive and multiplicative identities.
@ararslan suggests adding @eval $(f)(::Type{Missing}) = missing to the loop.
The text was updated successfully, but these errors were encountered:
Good question. It sounds a bit weird that iszero(zero(missing)) and zero(missing) == 0 would not be true. But maybe that's not an issue. Can you show an actual use case?
I just encountered this when doing correlation plots (from StatsPlots).
It seems to arise easily by calling Statistics.cor on data with missing. Reproducing example:
julia> import Statistics: cor
julia> cor([zeros(1,1); missing])
ERROR: UndefVarError: T not defined
EDIT: for this use case, missing seems to be the right answer (at least for oneunit):
Base.oneunit(::Type{Missing}) = missing
x = rand(10)
cor([[x;missing] [0.0;x] [x;0.0] [x;0.0]])
zero(Missing)
currently fails, as doesone(Missing)
andoneunit(Missing)
:The error comes from this code in base/missing.jl:
Perhaps
zero(::Missing)
andone(::Missing)
should bemissing
, sincemissing + missing == missing
and the same for*
and those two methods give you the additive and multiplicative identities.@ararslan suggests adding
@eval $(f)(::Type{Missing}) = missing
to the loop.The text was updated successfully, but these errors were encountered: