From cad757e5d759e5b080e581fd7c604f98a6f9599f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20M=C3=BCller-Widmann?= Date: Sun, 11 Jan 2026 21:26:14 +0100 Subject: [PATCH 1/2] Support JET@0.11 in tests --- Project.toml | 2 +- src/pairwise.jl | 2 +- test/jet.jl | 33 +++++++++++++++++---------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Project.toml b/Project.toml index e03e66c65..5f006d3d9 100644 --- a/Project.toml +++ b/Project.toml @@ -21,7 +21,7 @@ StatsAPI = "82ae8749-77ed-4fe6-ae5f-f523153014b0" AliasTables = "1" DataAPI = "1" DataStructures = "0.10, 0.11, 0.12, 0.13, 0.14, 0.17, 0.18, 0.19" -JET = "0.9.18, 0.10" +JET = "0.9.18, 0.10, 0.11" LinearAlgebra = "<0.0.1, 1" LogExpFunctions = "0.3" Missings = "0.3, 0.4, 1.0" diff --git a/src/pairwise.jl b/src/pairwise.jl index c8023c6a2..876dd4c12 100644 --- a/src/pairwise.jl +++ b/src/pairwise.jl @@ -40,7 +40,7 @@ function check_vectors(x, y, skipmissing::Symbol) end end if m > 1 && n > 1 - indsx == indsy || + keys(first(x)) == keys(first(y)) || throw(ArgumentError("All input vectors must have the same indices")) end end diff --git a/test/jet.jl b/test/jet.jl index 78d06ebc7..6a8f01562 100644 --- a/test/jet.jl +++ b/test/jet.jl @@ -1,22 +1,23 @@ using StatsBase, Test import JET -# JET has only experimental support for Julia 1.12 currently -# It throws an internal `AssertionError` in the tests below -if VERSION < v"1.12-" - @testset "JET" begin - # Check that there are no undefined global references and undefined field accesses - JET.test_package("StatsBase"; target_defined_modules = true, mode = :typo) +@testset "JET" begin + # Check that there are no undefined global references and undefined field accesses + JET.test_package(StatsBase; target_modules = (StatsBase,), mode = :typo) - # Default error analysis for common problem fails since JET errors on interface definitions - # The (deprecated) `model_response(::StatisticalModel)` calls the interface - # function `response(::StatisticalModel)` for which no method exists yet - # Note: This analysis is not enough strict to guarantee that there are no runtime errors! - # Ref https://github.com/aviatesk/JET.jl/issues/495 - res = JET.report_package("StatsBase"; target_defined_modules = true, mode = :basic, toplevel_logger = nothing) - println(res) - reports = JET.get_reports(res) - @test_broken isempty(reports) - @test length(reports) <= 1 + # Default error analysis + # Note: This analysis is not enough strict to guarantee that there are no runtime errors! + kwargs = if isdefined(JET, :LastFrameModuleExact) # JET@0.11 + (; target_modules = (StatsBase,)) + else + (; target_defined_modules = true) end + # The (deprecated) `model_response(::StatisticalModel)` calls the interface + # function `response(::StatisticalModel)` for which no method exists yet + # Ref https://github.com/aviatesk/JET.jl/issues/495 + res = JET.report_package(StatsBase; kwargs..., mode = :basic, toplevel_logger = nothing) + println(res) + reports = JET.get_reports(res) + @test_broken isempty(reports) + @test length(reports) <= 1 end From e36b8874178dac04d53617a8bb411b97e50e7476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20M=C3=BCller-Widmann?= Date: Wed, 17 Jun 2026 10:32:12 +0200 Subject: [PATCH 2/2] Guard `@irrational mad_constant` against re-expansion under JET 0.11 JET 0.11 re-executes a package's top-level code via Revise to extract method signatures, which re-expands the `IrrationalConstants.@irrational` macro. IrrationalConstants >= 0.2.6 throws at macro-expansion time when the generated type already exists, so the re-expansion errored in the JET tests. Wrap the definition in `@static if !isdefined(...)` so it is idempotent under re-expansion. `@static` only macroexpands the chosen branch, so the macro is skipped once the type exists (a runtime `if` would not help, since both branches are macroexpanded). Co-Authored-By: Claude Opus 4.8 (1M context) --- src/scalarstats.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/scalarstats.jl b/src/scalarstats.jl index bff0cec24..21e8b3221 100644 --- a/src/scalarstats.jl +++ b/src/scalarstats.jl @@ -524,7 +524,11 @@ function sem(x::AbstractArray, weights::ProbabilityWeights; mean=nothing) end # Median absolute deviation -IrrationalConstants.@irrational mad_constant 1.4826022185056018 BigFloat("1.482602218505601860547076529360423431326703202590312896536266275245674447622701") +# `@static`-guard so the definition is idempotent: JET re-expands top-level code via +# Revise, and IrrationalConstants >= 0.2.6 throws if the type is already defined. +@static if !isdefined(@__MODULE__, :Mad_constant) + IrrationalConstants.@irrational mad_constant 1.4826022185056018 BigFloat("1.482602218505601860547076529360423431326703202590312896536266275245674447622701") +end """ mad(x; center=median(x), normalize=true)