StatsBase.jl
StatsBase.jl copied to clipboard
`countmap` weird behaviour for -0.0
t = [0., -0.]
ct = countmap(t, [1 for e in t])
will output:
Dict{Float64, Int64} with 2 entries:
0.0 => 1
-0.0 => 1
Changing t to Integers
t = [0, -0]
ct = countmap(t, [1 for e in t])
or removing the weights
t = [0., -0.]
ct = countmap(t)
leads to the expected behaviour:
Dict{Float64, Int64} with 1 entry:
0.0 => 2
Now all of this does not seem problematic until you start changing the keys, e.g.
Dict(keys(ct) .+ 1 .=> values(ct))
leads to
Dict{Float64, Int64} with 1 entry:
1.0 => 1
in the first case, instead of
Dict{Float64, Int64} with 1 entry:
1.0 => 2
Therefore I think this is not the intended behaviour. To be fair this could also be interpreted as a bug in the general Dict routine.