JeffreySarnoff / RollingFunctions.jl

Roll a window over data; apply a function over the window.
MIT License
114 stars 6 forks source link

no method matching AbstractFloat(::Type{Union{Missing, Float64}}) #11

Closed xgdgsc closed 5 years ago

xgdgsc commented 5 years ago

After upgrading to julia 1.0.3 from 1.0.2. I get error with code that used to work before:

A = [missing;1;2;3;4;5;0.000000001; -100;0; missing; NaN]
using RollingFunctions
running(sum, A, 2)
ERROR: MethodError: no method matching AbstractFloat(::Type{Union{Missing, Float64}})
Closest candidates are:
  AbstractFloat(::Bool) at float.jl:250
  AbstractFloat(::Int8) at float.jl:251
  AbstractFloat(::Int16) at float.jl:252
  ...
Stacktrace:
 [1] float(::Type) at ./float.jl:269
 [2] running(::Function, ::Array{Union{Missing, Float64},1}, ::Int64) at /home/gsc/.julia/packages/RollingFunctions/DLRrJ/src/running.jl:8
 [3] top-level scope at none:0

Adding RollingFunctions.float(::Type{Union{T,Missing}}) where {T} = Base.float(T) from https://github.com/JuliaLang/julia/issues/29693 seems a partial workaround for me.

xgdgsc commented 5 years ago

I don' t know if we should add result=convert(Array{Union{Missing,Float64}} to places like
https://github.com/JeffreySarnoff/RollingFunctions.jl/blob/master/src/rolling.jl#L50 . Didn' t find why it worked before. Now it shows error with arrays contain missing:

MethodError: Cannot `convert` an object of type Missing to an object of type Float64
Closest candidates are:
  convert(::Type{T<:Number}, !Matched::T<:Number) where T<:Number at number.jl:6
  convert(::Type{T<:Number}, !Matched::Number) where T<:Number at number.jl:7
  convert(::Type{T<:Number}, !Matched::Base.TwicePrecision) where T<:Number at twiceprecision.jl:250
  ...

Stacktrace:
 [1] setindex!(::Array{Float64,1}, ::Missing, ::Int64) at ./array.jl:769
 [2] tapers(::typeof(sum), ::Array{Union{Missing, Float64},1}) at /home/dev/.julia/packages/RollingFunctions/DLRrJ/src/rolling.jl:52
 [3] running(::Function, ::Array{Union{Missing, Float64},1}, ::Int64) at /home/dev/.julia/packages/RollingFunctions/DLRrJ/src/running.jl:10
 [4] top-level scope at In[16]:1
JeffreySarnoff commented 5 years ago

I had a bunch of edits (not current master, an earlier one) that covered missings comprehensively and works with Julia v1.1-dev but does not precompile with Julia v1.0.3. Im considering waiting for v1.1 and using those. What do you think.

xgdgsc commented 5 years ago

That' s fine for me. Currently using my local simple implementation.

JeffreySarnoff commented 5 years ago

actually -- it seems sorted out now. Please try current master and let me know if it works for you.

JeffreySarnoff commented 5 years ago

works