Skip to content

Commit e7333de

Browse files
xiaodaighnalimilan
authored andcommitted
rle for Union{Missing, T} (JuliaLang#521)
1 parent b3f9d19 commit e7333de

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/misc.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function rle(v::AbstractVector{T}) where T
3131
i = 2
3232
@inbounds while i <= n
3333
vi = v[i]
34-
if vi == cv
34+
if isequal(vi, cv)
3535
cl += 1
3636
else
3737
push!(vals, cv)

test/misc.jl

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ z = BitArray([true, true, false, false, true])
2020
@test vals == [true, false, true]
2121
@test lens == [2, 2, 1]
2222

23+
z = [1, 1, 2, missing, 2, 3, 1, missing, missing, 3, 3, 3, 3]
24+
vals, lens = rle(z)
25+
@test isequal(vals, [1, 2, missing, 2, 3, 1, missing, 3])
26+
@test lens == [2, 1, 1, 1, 1, 1, 2, 4]
27+
@test isequal(inverse_rle(vals, lens), z)
28+
2329
# levelsmap
2430
a = [1, 1, 2, 2, 2, 3, 1, 2, 2, 3, 3, 3, 3, 2]
2531
b = [true, false, false, true, false, true, true, false]

0 commit comments

Comments
 (0)