Skip to content

Commit 552e3ba

Browse files
authored
Fix bug in interaction of scalar terms for row tables (#206)
* add test to reproduce #185 * only call `vec` if necessary in `kron_insideout` * use length(size()) instead of length() * use isa AbstractArray check instead of dims * bump patch version
1 parent 6c757d4 commit 552e3ba

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
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.17"
3+
version = "0.6.18"
44

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

src/terms.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,9 @@ reshape_last_to_i(i, a::AbstractMatrix) = reshape(a, size(a,1), ones(Int, i-1)..
510510
# table, some will be vectors, possibly some matrices
511511
function kron_insideout(op::Function, args...)
512512
args = (reshape_last_to_i(i,a) for (i,a) in enumerate(args))
513-
vec(broadcast(op, args...))
513+
out = broadcast(op, args...)
514+
# flatten array output to vector
515+
out isa AbstractArray ? vec(out) : out
514516
end
515517

516518
function row_kron_insideout(op::Function, args...)

test/modelmatrix.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,4 +398,10 @@
398398
@test_throws ArgumentError modelcols(f, t)
399399
end
400400

401+
@testset "#185 - interactions of scalar terms for row tables" begin
402+
t = (a = rand(10), b = rand(10), c = rand(10))
403+
f = apply_schema(@formula(0 ~ a&b&c), schema(t))
404+
@test vec(modelcols(f.rhs, t)) == modelcols.(Ref(f.rhs), Tables.rowtable(t))
405+
end
406+
401407
end

0 commit comments

Comments
 (0)