Skip to content

Commit

Permalink
rle for Union{Missing, T} (JuliaLang#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaodaigh authored and nalimilan committed Sep 19, 2019
1 parent b3f9d19 commit e7333de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function rle(v::AbstractVector{T}) where T
i = 2
@inbounds while i <= n
vi = v[i]
if vi == cv
if isequal(vi, cv)
cl += 1
else
push!(vals, cv)
Expand Down
6 changes: 6 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ z = BitArray([true, true, false, false, true])
@test vals == [true, false, true]
@test lens == [2, 2, 1]

z = [1, 1, 2, missing, 2, 3, 1, missing, missing, 3, 3, 3, 3]
vals, lens = rle(z)
@test isequal(vals, [1, 2, missing, 2, 3, 1, missing, 3])
@test lens == [2, 1, 1, 1, 1, 1, 2, 4]
@test isequal(inverse_rle(vals, lens), z)

# levelsmap
a = [1, 1, 2, 2, 2, 3, 1, 2, 2, 3, 3, 3, 3, 2]
b = [true, false, false, true, false, true, true, false]
Expand Down

0 comments on commit e7333de

Please sign in to comment.