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

Cannot compute quantile(x::Array{Millisecond,1}) #53

Open
ianfiske opened this issue Sep 25, 2020 · 3 comments · May be fixed by #54
Open

Cannot compute quantile(x::Array{Millisecond,1}) #53

ianfiske opened this issue Sep 25, 2020 · 3 comments · May be fixed by #54

Comments

@ianfiske
Copy link

ms = Millisecond.(1:10)
quantile(ms, 0.5)

gives

ERROR: MethodError: no method matching isnan(::Millisecond)
Closest candidates are:
  isnan(::BigFloat) at mpfr.jl:881
  isnan(::Missing) at missing.jl:100
  isnan(::Float16) at float.jl:537
  ...
Stacktrace:
 [1] _quantilesort!(::Array{Millisecond,1}, ::Bool, ::Float64, ::Float64) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Statistics/src/Statistics.jl:960
 [2] quantile!(::Array{Millisecond,1}, ::Float64; sorted::Bool, alpha::Float64, beta::Float64) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Statistics/src/Statistics.jl:943
 [3] quantile(::Array{Millisecond,1}, ::Float64; sorted::Bool, alpha::Float64, beta::Float64) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Statistics/src/Statistics.jl:1052
 [4] quantile(::Array{Millisecond,1}, ::Float64) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Statistics/src/Statistics.jl:1052
 [5] top-level scope at REPL[14]:1
 [6] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1088

on Julia 1.5.2.

The root issue is of course

julia> isnan(Millisecond(1))
ERROR: MethodError: no method matching isnan(::Millisecond)
Closest candidates are:
  isnan(::BigFloat) at mpfr.jl:881
  isnan(::Missing) at missing.jl:100
  isnan(::Float16) at float.jl:537

since _quantilesort! calls isnan(x[end])

@ianfiske
Copy link
Author

Would

isnan(::TimePeriod) = false

be an acceptable fix?

@mschauer
Copy link
Member

mschauer commented Sep 25, 2020

Unitful defines isnan https://github.com/PainterQubits/Unitful.jl/blob/2be7e0692cafd948b66132920ee407b73220717f/src/quantities.jl
and base should perhaps define it for TimePeriods as well.

@nalimilan
Copy link
Member

As noted at JuliaLang/julia#37748, I think we'd better check applicable or method_exists, as we don't want to define isnan on all types that quantile should support.

@ianfiske ianfiske linked a pull request Sep 29, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants