Skip to content

Commit

Permalink
wrap level in categorical column in tuple (#20)
Browse files Browse the repository at this point in the history
wrap level in categorical column in tuple to avoid splatting levels (e.g. strings)
  • Loading branch information
tiemvanderdeure authored Sep 23, 2024
1 parent 74c58d3 commit e494612
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/model_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit e494612

Please sign in to comment.