It seems StatsBase.histrange has some extra logic in it, but I don’t know the reason why.
The documentation states
nbins: if noedgesargument is supplied, the approximate number of bins to use along each dimension (can be either a single integer, or a tuple of integers).
One can, however, provide the edges directly to avoid this.
julia> fit(Histogram, rand(100), range(0.0,1.0,length=7+1))
Histogram{Int64, 1, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}}}
edges:
0.0:0.14285714285714285:1.0
weights: [13, 9, 13, 18, 16, 19, 12]
closed: left
isdensity: false
julia> fit(Histogram, rand(100), range(0.0,1.0,length=10+1))
Histogram{Int64, 1, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}}}
edges:
0.0:0.1:1.0
weights: [8, 10, 9, 8, 7, 16, 11, 10, 13, 8]
closed: left
isdensity: false
I also found an issue regarding this topic: