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

propagate NaN value in median #164

Merged
merged 2 commits into from
May 26, 2024
Merged

Conversation

aplavin
Copy link
Contributor

@aplavin aplavin commented Mar 13, 2024

Propagate a NaN value from the input array, instead of creating a NaN anew.

Fixes this error, for example:

julia> using Statistics, Unitful

julia> median([NaN*u"m"])
ERROR: DimensionError: m and NaN are not dimensionally compatible.
Stacktrace:
 [1] convert(::Type{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}, x::Float64)
   @ Unitful ~/.julia/packages/Unitful/R4J37/src/conversion.jl:106
 [2] median!(v::Vector{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}})
   @ Statistics ~/.julia/juliaup/julia-1.10.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Statistics/src/Statistics.jl:815
 [3] _median
   @ ~/.julia/juliaup/julia-1.10.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Statistics/src/Statistics.jl:878 [inlined]
 [4] median(v::Vector{Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}})
   @ Statistics ~/.julia/juliaup/julia-1.10.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Statistics/src/Statistics.jl:874
 [5] top-level scope
   @ REPL[3]:1

@codecov-commenter
Copy link

codecov-commenter commented Mar 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.03%. Comparing base (68869af) to head (cc11ea9).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #164      +/-   ##
==========================================
+ Coverage   97.01%   97.03%   +0.02%     
==========================================
  Files           2        2              
  Lines         435      439       +4     
==========================================
+ Hits          422      426       +4     
  Misses         13       13              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aplavin
Copy link
Contributor Author

aplavin commented Mar 27, 2024

bump

@aplavin
Copy link
Contributor Author

aplavin commented Apr 8, 2024

another bump

@aplavin
Copy link
Contributor Author

aplavin commented Apr 18, 2024

yet another bump

@aplavin
Copy link
Contributor Author

aplavin commented Apr 20, 2024

added tests: this PR makes NaN handling in median() consistent with others like mean() and sum()

@aplavin
Copy link
Contributor Author

aplavin commented Apr 30, 2024

yet yet another bump

@aplavin
Copy link
Contributor Author

aplavin commented May 16, 2024

yet yet yet another bump...

@andreasnoack andreasnoack merged commit 6e3d223 into JuliaStats:master May 26, 2024
16 checks passed
@aplavin aplavin deleted the patch-1 branch June 17, 2024 17:56
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

Successfully merging this pull request may close these issues.

3 participants