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

quantile is broken with unitful quantities #883

Open
juliohm opened this issue Jul 24, 2023 · 1 comment
Open

quantile is broken with unitful quantities #883

juliohm opened this issue Jul 24, 2023 · 1 comment

Comments

@juliohm
Copy link

juliohm commented Jul 24, 2023

The quantile function with unitful quantities works fine without weights:

julia> x = rand(10) .* 1u"m"
10-element Vector{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}:
   0.4560455822873759 m
   0.4307569757744304 m
   0.4840857672199611 m
   0.7853776015820557 m
   0.5865440640498318 m
  0.15996668178343565 m
 0.042204899384880146 m
   0.3310111766347721 m
   0.8691765138294111 m
   0.5325561348479884 m

julia> quantile(x, 0.5)
0.4700656747536685 m

However, if we try to pass weights, it crashes:

julia> quantile(x, Weights(1:10), 0.5)
ERROR: MethodError: no method matching quantile(::Vector{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}, ::Weights{Int64, Int64, UnitRange{Int64}}, ::Float64)

Closest candidates are:
  quantile(::AbstractVector{T} where T<:Real, ::AbstractWeights{var"#s42", T} where {var"#s42"<:Real, T<:Real}, ::Number)
   @ StatsBase ~/.julia/packages/StatsBase/XgjIN/src/weights.jl:772
  quantile(::AbstractVector{V}, ::AbstractWeights{W, T} where T<:Real, ::AbstractVector{T} where T<:Real) where {V, W<:Real}
   @ StatsBase ~/.julia/packages/StatsBase/XgjIN/src/weights.jl:700
  quantile(::AbstractVector, ::Any; sorted, alpha, beta)
   @ Statistics ~/.julia/juliaup/julia-1.9.2+0.x64.linux.gnu/share/julia/stdlib/v1.9/Statistics/src/Statistics.jl:1073
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[15]:1

This method definition is too restrictive:

function quantile(v::AbstractVector{<:Real}{V}, w::AbstractWeights{W}, p::AbstractVector{<:Real}) where {V,W<:Real}

@ParadaCarleton
Copy link
Contributor

ParadaCarleton commented Aug 28, 2023

where T<:Real

Non-Real Unitful units strike again...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants