Skip to content

Commit 8f54d2b

Browse files
authored
enforce that levels are unique for ContrastsMatrix (#231)
* enforce that levels are unique for ContrastsMatrix * add test + bump patch version
1 parent d8c882c commit 8f54d2b

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StatsModels"
22
uuid = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
3-
version = "0.6.23"
3+
version = "0.6.24"
44

55
[deps]
66
DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"

src/contrasts.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ struct ContrastsMatrix{C <: AbstractContrasts, T, U}
111111
termnames::Vector{U},
112112
levels::Vector{T},
113113
contrasts::C) where {U,T,C <: AbstractContrasts}
114+
allunique(levels) || throw(ArgumentError("levels must be all unique, got $(levels)"))
114115
invindex = Dict{T,Int}(x=>i for (i,x) in enumerate(levels))
115116
new{C,T,U}(matrix, termnames, levels, contrasts, invindex)
116117
end

test/contrasts.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,9 @@
332332
@test_throws MethodError ContrastsCoding(rand(4,3), base=base)
333333

334334
end
335+
336+
@testset "Non-unique levels" begin
337+
@test_throws ArgumentError ContrastsMatrix(DummyCoding(), ["a", "a", "b"])
338+
end
339+
335340
end

0 commit comments

Comments
 (0)