Skip to content

Commit 4c9e559

Browse files
authored
Raise DimensionMismatch if lengths don't match (#922)
1 parent 5a3aaa6 commit 4c9e559

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

src/misc.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ run lengths.
5959
"""
6060
function inverse_rle(vals::AbstractVector{T}, lens::AbstractVector{<:Integer}) where T
6161
m = length(vals)
62-
length(lens) == m || raise_dimerror()
62+
mlens = length(lens)
63+
mlens == m || throw(DimensionMismatch(
64+
"number of vals ($m) does not match the number of lens ($mlens)"))
6365
n = sum(lens)
6466
n >= 0 || throw(ArgumentError("lengths must be non-negative"))
6567

src/ranking.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
function _check_randparams(rks, x, p)
1010
n = length(rks)
11-
length(x) == length(p) == n || raise_dimerror()
11+
nx = length(x)
12+
np = length(p)
13+
nx == np == n || throw(
14+
DimensionMismatch("lengths of x $nx and p $np do not match that of ranks $n"))
1215
return n
1316
end
1417

test/misc.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ z = [1, 1, 2, 2, 2, 3, 1, 2, 2, 3, 3, 3, 3]
99
@test lens == [2, 3, 1, 1, 2, 4]
1010
@test inverse_rle(vals, lens) == z
1111
@test_throws ArgumentError inverse_rle(vals, fill(-1, length(lens)))
12+
@test_throws DimensionMismatch inverse_rle(vals, [1])
1213

1314
z = [true, true, false, false, true, false, true, true, true]
1415
vals, lens = rle(z)

test/ranking.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ s = ["c", "a", "b", "d", "d", "b", "e", "d"] # s is a vector of strings ordered
3737
@test tiedrank(s) == tiedrank(x)
3838
@test tiedrank(x, rev = true) == tiedrank(-x)
3939
@test tiedrank(x, lt = (x, y) -> isless(y, x)) == tiedrank(-x)
40+
41+
42+
@test_throws DimensionMismatch StatsBase._check_randparams([1,2], [1,2], [1])

0 commit comments

Comments
 (0)