StatsBase.jl icon indicating copy to clipboard operation
StatsBase.jl copied to clipboard

StatsBase.sample should warn about weights containing Inf/NaN

Open xiruizhao opened this issue 4 years ago • 4 comments

https://github.com/JuliaStats/StatsBase.jl/blob/08d4b77a4b42ef8cadb67b98da65e7fbd9959e0b/src/sampling.jl#L499-L500 Perhaps add something like

swv = sum(wv)
isfinite(swv) || throw(DomainError(swv, "weights sum to $swv"))

xiruizhao avatar Mar 16 '21 07:03 xiruizhao

Good idea. Would you make a pull request?

nalimilan avatar Mar 20 '21 14:03 nalimilan

I recently ran into a bug due to this issue. A warning about Inf weights would have helped me to find the problem faster. I see the PR wasn't accepted though. Are there still plans to implement this?

ruairidhs avatar Jul 12 '22 16:07 ruairidhs

Actually the PR wasn't rejected, it was closed by its author (I don't know why). Would you be willing to make a new PR with its contents?

nalimilan avatar Jul 12 '22 17:07 nalimilan

Actually the PR wasn't rejected, it was closed by its author (I don't know why). Would you be willing to make a new PR with its contents?

#814

ruairidhs avatar Jul 14 '22 14:07 ruairidhs