StatsBase.jl sample size > 31 throws error

I’m running into an issue that I’m hoping someone can help me understand. I have a 1308 x 22 DataFrame that I’m trying to sample from with StatsBase. All is well and fine as long as n <= 31.

The code looks like this:

julia> df
1308×22 DataFrame. Omitted printing of 8 columns
...

julia> wv = FrequencyWeights(df.PWORWGT)
1308-element FrequencyWeights{Int64,Int64,Array{Int64,1}}:
...

julia> sample(axes(df,1), wv, 31)
31-element Array{Int64,1}:
...

# If I change 31 to 32, I get this:

julia> sample(axes(df,1), wv, 32)
ERROR: MethodError: no method matching make_alias_table!(::Array{Int64,1}, ::Int64, ::Array{Float64,1}, ::Array{Int64,1})
Closest candidates are:
  make_alias_table!(::AbstractArray{Float64,1}, ::Float64, ::AbstractArray{Float64,1}, ::AbstractArray{Int64,1}) at C:\Users\mthel\.julia\packages\StatsBase\DyWPR\src\sampling.jl:471
Stacktrace:
 [1] alias_sample!(::Random._GLOBAL_RNG, ::Base.OneTo{Int64}, ::FrequencyWeights{Int64,Int64,Array{Int64,1}}, ::Array{Int64,1}) at C:\Users\mthel\.julia\packages\StatsBase\DyWPR\src\sampling.jl:533
 [2] #sample!#153(::Bool, ::Bool, ::typeof(sample!), ::Random._GLOBAL_RNG, ::Base.OneTo{Int64}, ::FrequencyWeights{Int64,Int64,Array{Int64,1}}, ::Array{Int64,1}) at C:\Users\mthel\.julia\packages\StatsBase\DyWPR\src\sampling.jl:768
 [3] #sample#154 at .\none:0 [inlined]
 [4] #sample at .\none:0 [inlined]
 [5] #sample#155 at C:\Users\mthel\.julia\packages\StatsBase\DyWPR\src\sampling.jl:789 [inlined]
 [6] sample(::Base.OneTo{Int64}, ::FrequencyWeights{Int64,Int64,Array{Int64,1}}, ::Int64) at C:\Users\mthel\.julia\packages\StatsBase\DyWPR\src\sampling.jl:789
 [7] top-level scope at REPL[29]:1

Is this a bug that I should report, or am I missing something? If I remove the weight vector, it works fine, regardless of what number I pick for n.

An MWE would be helpful (you don’t need the df, since you just use its dimension information).

Here’s a MWE:

using DataFrames
using Random
using StatsBase

df=DataFrame(a=rand(1308), b=rand(1308), c=rand(1308), d=collect(1:2:2616))
wv = FrequencyWeights(df.d)

With n=31 it works just fine:

julia> sample(axes(df,1), wv, 31)
31-element Array{Int64,1}:
  807
  283
 1219
  793
 1180
  966
  510
  997
  647
 1052
 1181
  952
    ⋮
 1012
  507
  994
  447
 1297
 1293
  768
  147
  667
 1248
  924
  477

At n=32, the error:

julia> sample(axes(df,1), wv, 32)
ERROR: MethodError: no method matching make_alias_table!(::Array{Int64,1}, ::Int64, ::Array{Float64,1}, ::Array{Int64,1})
Closest candidates are:
  make_alias_table!(::AbstractArray{Float64,1}, ::Float64, ::AbstractArray{Float64,1}, ::AbstractArray{Int64,1}) at C:\Users\mthel\.julia\packages\StatsBase\DyWPR\src\sampling.jl:471
Stacktrace:
 [1] alias_sample!(::Random._GLOBAL_RNG, ::Base.OneTo{Int64}, ::FrequencyWeights{Int64,Int64,Array{Int64,1}}, ::Array{Int64,1}) at C:\Users\mthel\.julia\packages\StatsBase\DyWPR\src\sampling.jl:533
 [2] #sample!#153(::Bool, ::Bool, ::typeof(sample!), ::Random._GLOBAL_RNG, ::Base.OneTo{Int64}, ::FrequencyWeights{Int64,Int64,Array{Int64,1}}, ::Array{Int64,1}) at C:\Users\mthel\.julia\packages\StatsBase\DyWPR\src\sampling.jl:768
 [3] #sample#154 at .\none:0 [inlined]
 [4] #sample at .\none:0 [inlined]
 [5] #sample#155 at C:\Users\mthel\.julia\packages\StatsBase\DyWPR\src\sampling.jl:789 [inlined]
 [6] sample(::Base.OneTo{Int64}, ::FrequencyWeights{Int64,Int64,Array{Int64,1}}, ::Int64) at C:\Users\mthel\.julia\packages\StatsBase\DyWPR\src\sampling.jl:789
 [7] top-level scope at REPL[16]:1

Nevermind, my brain was too exhausted yesterday. The error message tells me what I need to do:

 # changed column d to Float
df=DataFrame(a=rand(1308), b=rand(1308), c=rand(1308), d=collect(1.0:2.0:2616.0))
wv = FrequencyWeights(df.d)

Now,

julia> sample(axes(df,1), wv, 32)
32-element Array{Int64,1}:
  118
  996
 1255
 1148
 1071
  988
  573
  432
  700
 1067
  721
  842
    ⋮
  669
  615
  524
  896
 1147
 1277
 1020
 1042
 1190
 1236
 1084
 1021

Seems like it should just work though, regardless of whether or not my data are Int/Float.