Skip to content

Commit c7f0db7

Browse files
authored
Specialize apply_schema to Schema for lead/lag (#152)
* specialize lead/lag apply schema to Schema * add test to detect ambiguities in StatsModels * test ambiguities first, leave broken test in extensions adding additional methods in the extensions tests creates ambiguities :(((
1 parent 31e63e2 commit c7f0db7

File tree

5 files changed

+12
-3
lines changed

5 files changed

+12
-3
lines changed

src/StatsModels.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ export
5858
include("traits.jl")
5959
include("contrasts.jl")
6060
include("terms.jl")
61-
include("temporal_terms.jl")
6261
include("schema.jl")
62+
include("temporal_terms.jl")
6363
include("formula.jl")
6464
include("modelframe.jl")
6565
include("statsmodel.jl")

src/temporal_terms.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct LeadLagTerm{T<:AbstractTerm, F<:Union{typeof(lead), typeof(lag)}} <: Abst
2626
nsteps::Int
2727
end
2828

29-
function apply_schema(t::FunctionTerm{F}, sch, ctx::Type) where F<:Union{typeof(lead), typeof(lag)}
29+
function apply_schema(t::FunctionTerm{F}, sch::Schema, ctx::Type) where F<:Union{typeof(lead), typeof(lag)}
3030
opname = string(nameof(F.instance))
3131
if length(t.args_parsed) == 1 # lag(term)
3232
term_parsed = first(t.args_parsed)

test/ambiguity.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@testset "Ambiguity detection" begin
2+
@test isempty(Test.detect_ambiguities(StatsModels))
3+
end

test/extension.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,9 @@ end
9393
@testset "Fallback" begin
9494
@test_throws ArgumentError modelcols(DummyTerm(), (a=[1], ))
9595
end
96+
97+
@testset "Ambiguity detection" begin
98+
# ambiguities are introduced by adding additional methods here
99+
@test_broken isempty(Test.detect_ambiguities(StatsModels))
100+
end
96101
end

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ using StatsBase
88

99
using StatsModels: ContrastsMatrix
1010

11-
my_tests = ["formula.jl",
11+
my_tests = ["ambiguity.jl",
12+
"formula.jl",
1213
"terms.jl",
1314
"temporal_terms.jl",
1415
"schema.jl",

0 commit comments

Comments
 (0)