Skip to content

Commit b41b2f4

Browse files
authored
Fix countmap with -0.0 (#831)
Radix sort algorithm treated `-0.0` and `0.0` as equal, but the dict algorithm treated them as different.
1 parent f7129c9 commit b41b2f4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/counts.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ function _addcounts_radix_sort_loop!(cm::Dict{T}, sx::AbstractVector{T}) where T
356356
# adding into the Dict
357357
@inbounds for i in start_i+1:lastindex(sx)
358358
sxi = sx[i]
359-
if last_sx != sxi
359+
if !isequal(last_sx, sxi)
360360
cm[last_sx] = get(cm, last_sx, 0) + i - start_i
361361
last_sx = sxi
362362
start_i = i

test/counts.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ end
172172
@test cm_tx_missing == countmap(tx) == Dict(typemin(T) => 1, typemax(T) => 1, 8 => 2, 19 => 1)
173173
@test cm_tx_missing isa Dict{T, Int}
174174
end
175+
176+
# -0.0 and NaN
177+
@test countmap([0.0, -0.0, 0.0, -0.0, -0.0], alg=:dict) ==
178+
countmap([0.0, -0.0, 0.0, -0.0, -0.0], alg=:radixsort) ==
179+
Dict(0.0 => 2, -0.0 => 3)
180+
@test countmap([NaN, NaN], alg=:dict) ==
181+
countmap([NaN, NaN], alg=:radixsort) ==
182+
Dict(NaN => 2)
175183
end
176184

177185
@testset "views" begin

0 commit comments

Comments
 (0)