Skip to content

Commit 50f0ac9

Browse files
authored
fix for Grouping() with latest CategoricalArrays (#860)
* fix for Grouping() with latest CategoricalArrays * NEWS * patch bump * d'oh
1 parent 46b5900 commit 50f0ac9

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
MixedModels v5.0.1 Release Notes
2+
==============================
3+
- Fixes a method error with `Grouping()` contrasts when used with recent CategoricalArray releases. [#860]
4+
15
MixedModels v5.0.0 Release Notes
26
==============================
37
- Optimization is now performed _without constraints_. In a post-fitting step, the Cholesky factor is canonicalized to have non-negative diagonal elements. [#840]
@@ -685,3 +689,4 @@ Package dependencies
685689
[#856]: https://github.com/JuliaStats/MixedModels.jl/issues/856
686690
[#857]: https://github.com/JuliaStats/MixedModels.jl/issues/857
687691
[#858]: https://github.com/JuliaStats/MixedModels.jl/issues/858
692+
[#860]: https://github.com/JuliaStats/MixedModels.jl/issues/860

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MixedModels"
22
uuid = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316"
33
author = ["Phillip Alday <me@phillipalday.com>", "Douglas Bates <dmbates@gmail.com>"]
4-
version = "5.0.0"
4+
version = "5.0.1"
55

66
[deps]
77
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
@@ -46,6 +46,7 @@ MixedModelsPRIMAExt = ["PRIMA"]
4646
Aqua = "0.8"
4747
Arrow = "1, 2"
4848
BSplineKit = "0.17, 0.18, 0.19"
49+
CategoricalArrays = "0.10, 1"
4950
Compat = "4.10"
5051
DataAPI = "1"
5152
DataFrames = "1"
@@ -84,6 +85,7 @@ julia = "1.10"
8485

8586
[extras]
8687
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
88+
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
8789
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
8890
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
8991
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
@@ -96,4 +98,4 @@ Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
9698
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
9799

98100
[targets]
99-
test = ["Aqua", "DataFrames", "ExplicitImports", "FiniteDiff", "ForwardDiff", "InteractiveUtils", "PRIMA", "StableRNGs", "Suppressor", "Test"]
101+
test = ["Aqua", "CategoricalArrays", "DataFrames", "ExplicitImports", "FiniteDiff", "ForwardDiff", "InteractiveUtils", "PRIMA", "StableRNGs", "Suppressor", "Test"]

src/grouping.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ end
3131
function StatsModels.ContrastsMatrix(
3232
contrasts::Grouping, levels::AbstractVector
3333
)
34+
levels = convert(Vector, levels)
3435
return StatsModels.ContrastsMatrix(zeros(0, 0), levels, levels, contrasts)
3536
end
3637

test/grouping.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using MixedModels
22
using StatsModels
33
using Test
44

5+
using CategoricalArrays: categorical
56
using MixedModels: schematize
67
using StatsModels: ContrastsMatrix, FullDummyCoding
78

@@ -14,8 +15,6 @@ end
1415
d = (; y=rand(2_000_000),
1516
grp=string.([1:1_000_000; 1:1_000_000]),
1617
outer=rand('A':'z', 2_000_000))
17-
## OOM seems to result in the process being killed on Mac so this messes up CI
18-
# @test_throws OutOfMemoryError schema(d)
1918
sch = schema(d, Dict(:grp => Grouping()))
2019
t = sch[term(:grp)]
2120
@test t isa CategoricalTerm{Grouping}
@@ -27,6 +26,16 @@ end
2726

2827
@test all(t.contrasts.invindex[lev] == i for (i, lev) in enumerate(levs))
2928
@test all(t.contrasts.levels[i] == lev for (i, lev) in enumerate(levs))
29+
30+
d = (; y=rand(20),
31+
grp=categorical([1:10; 1:10]))
32+
sch = schema(d, Dict(:grp => Grouping()))
33+
t = sch[term(:grp)]
34+
@test t isa CategoricalTerm{Grouping}
35+
@test size(t.contrasts.matrix) == (0, 0)
36+
@test length(t.contrasts.levels) == 10
37+
@test_throws ErrorException StatsModels.modelcols(t, (a=1.0,))
38+
3039
end
3140

3241
@testset "Auto application of Grouping()" begin

0 commit comments

Comments
 (0)