From e494612b629d4bedb1abfd09a2d5b32b27d45548 Mon Sep 17 00:00:00 2001 From: Tiem van der Deure Date: Mon, 23 Sep 2024 14:11:25 +0200 Subject: [PATCH] wrap level in categorical column in tuple (#20) wrap level in categorical column in tuple to avoid splatting levels (e.g. strings) --- src/model_matrix.jl | 2 +- test/runtests.jl | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/model_matrix.jl b/src/model_matrix.jl index f6e1cda..c9a260f 100644 --- a/src/model_matrix.jl +++ b/src/model_matrix.jl @@ -12,7 +12,7 @@ _feature_columns(cont_vars, cat_vars, f::LinearFeature, nk) = [ModelMatrixColumn _feature_columns(cont_vars, cat_vars, f::QuadraticFeature, nk) = [ModelMatrixColumn(f, k) for k in keys(cont_vars)] function _feature_columns(cont_vars, cat_vars, f::CategoricalFeature, nk) mapreduce(hcat, keys(cat_vars)) do k - [ModelMatrixColumn(f, k, x) for x in CategoricalArrays.levels(cat_vars[k])] + [ModelMatrixColumn(f, k, (x,)) for x in CategoricalArrays.levels(cat_vars[k])] end end diff --git a/test/runtests.jl b/test/runtests.jl index cf94cae..ed8e29a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,8 @@ -using Maxnet, Test, Statistics +using Maxnet, Test, Statistics, CategoricalArrays p_a, env = Maxnet.bradypus() +# Make the levels in ecoreg string to make sure that that works +env = merge(env, (; ecoreg = recode(env.ecoreg, (l => string(l) for l in levels(env.ecoreg))...))) env1 = map(e -> [e[1]], env) # just the first row @testset "utils" begin