Skip to content

Commit

Permalink
Fix inverse_rle with negative lengths (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Apr 26, 2023
1 parent 28f70ec commit 7928f90
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StatsBase"
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
authors = ["JuliaStats"]
version = "0.33.21"
version = "0.33.22"

[deps]
DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
Expand Down
5 changes: 4 additions & 1 deletion src/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ run lengths.
function inverse_rle(vals::AbstractVector{T}, lens::AbstractVector{<:Integer}) where T
m = length(vals)
length(lens) == m || raise_dimerror()
n = sum(lens)
n >= 0 || throw(ArgumentError("lengths must be non-negative"))

r = Vector{T}(undef, sum(lens))
r = Vector{T}(undef, n)
p = 0
@inbounds for i = 1 : m
j = lens[i]
j >= 0 || throw(ArgumentError("lengths must be non-negative"))
v = vals[i]
while j > 0
r[p+=1] = v
Expand Down
1 change: 1 addition & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ z = [1, 1, 2, 2, 2, 3, 1, 2, 2, 3, 3, 3, 3]
@test vals == [1, 2, 3, 1, 2, 3]
@test lens == [2, 3, 1, 1, 2, 4]
@test inverse_rle(vals, lens) == z
@test_throws ArgumentError inverse_rle(vals, fill(-1, length(lens)))

z = [true, true, false, false, true, false, true, true, true]
vals, lens = rle(z)
Expand Down

4 comments on commit 7928f90

@ararslan
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/82378

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.33.22 -m "<description of version>" 7928f90f14b34b1da24fae8de6da3a3efa5e3d55
git push origin v0.33.22

@andreasnoack
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has broken some packages because of the removed aliases so I've opened JuliaRegistries/General#82386 and I think we'll have to retag as 0.34.0

@ararslan
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welp. It's unfortunate that other packages relied those undocumented, unexported, unnecessary type aliases.

Please sign in to comment.