From cae871ee3e592c7d049faa321ec6779735b77311 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Sat, 17 Jun 2023 15:34:49 +0200 Subject: [PATCH 1/6] Remove `Real` supertype from `PValue` and `TestStat` --- src/statmodels.jl | 27 ++------------------------- test/statmodels.jl | 23 ----------------------- 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/src/statmodels.jl b/src/statmodels.jl index 291b6e2e7..b77d82e77 100644 --- a/src/statmodels.jl +++ b/src/statmodels.jl @@ -55,7 +55,7 @@ end Show a p-value using 6 characters, either using the standard 0.XXXX representation or as , ≥, isless, isequal), - lhs in vals, rhs in vals - # make sure that T behaves like a Real, - # regardless of whether it's on the LHS, RHS or both - @test f(T(lhs), T(rhs)) == f(lhs, rhs) - @test f(lhs, T(rhs)) == f(lhs, rhs) - @test f(T(lhs), rhs) == f(lhs, rhs) - end - - # the (approximate) equality operators get a bit more attention - for T in [PValue, TestStat] - @test T(Rational(1,3)) ≈ T(1/3) - @test Rational(1,3) ≈ T(1/3) atol=0.01 - @test T(Rational(1,3)) isa Real - @test T(T(0.05)) === T(0.05) - @test hash(T(0.05)) == hash(0.05) - @test hash(T(0.05), UInt(42)) == hash(0.05, UInt(42)) - end -end - @test sprint(showerror, ConvergenceException(10)) == "failure to converge after 10 iterations." @test sprint(showerror, ConvergenceException(10, 0.2, 0.1)) == From 7d95adbb66ee1387664e5af4b8119ff33877278e Mon Sep 17 00:00:00 2001 From: David Widmann Date: Sat, 17 Jun 2023 15:35:04 +0200 Subject: [PATCH 2/6] Add tests with Aqua --- Project.toml | 4 +++- docs/Project.toml | 2 +- test/ambiguous.jl | 8 -------- test/aqua.jl | 11 +++++++++++ test/runtests.jl | 2 +- 5 files changed, 16 insertions(+), 11 deletions(-) delete mode 100644 test/ambiguous.jl create mode 100644 test/aqua.jl diff --git a/Project.toml b/Project.toml index cdecf98fb..b1c25b8e0 100644 --- a/Project.toml +++ b/Project.toml @@ -17,6 +17,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" StatsAPI = "82ae8749-77ed-4fe6-ae5f-f523153014b0" [compat] +Aqua = "0.6.3" DataAPI = "1" DataStructures = "0.10, 0.11, 0.12, 0.13, 0.14, 0.17, 0.18" LogExpFunctions = "0.3" @@ -26,6 +27,7 @@ StatsAPI = "1.2" julia = "1" [extras] +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" @@ -34,4 +36,4 @@ StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["BenchmarkTools", "Dates", "DelimitedFiles", "OffsetArrays", "StableRNGs", "Test"] +test = ["Aqua", "BenchmarkTools", "Dates", "DelimitedFiles", "OffsetArrays", "StableRNGs", "Test"] diff --git a/docs/Project.toml b/docs/Project.toml index ce890ef3d..918b9bb82 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,7 +1,7 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" StatsAPI = "82ae8749-77ed-4fe6-ae5f-f523153014b0" +StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" [compat] Documenter = "0.24" diff --git a/test/ambiguous.jl b/test/ambiguous.jl deleted file mode 100644 index 59014ca0f..000000000 --- a/test/ambiguous.jl +++ /dev/null @@ -1,8 +0,0 @@ -using StatsBase -using Test -using Statistics - -@testset "Ambiguities" begin - # Ambiguities with Base, Core, and stdlib Statistics introduced by this package - @test_broken isempty(detect_ambiguities(StatsBase, Base, Core, Statistics)) -end diff --git a/test/aqua.jl b/test/aqua.jl new file mode 100644 index 000000000..8b70c96f3 --- /dev/null +++ b/test/aqua.jl @@ -0,0 +1,11 @@ +using Aqua +using StatsBase +using Test + +@testset "Aqua" begin + Aqua.test_all( + StatsBase; + ambiguities=(exclude = [sort!],), # ambiguity in SortingAlgorithms (ignore) + piracy=(broken = true,), # should ignore `describe`, `pairwise`, `pairwise!` etc. which are owned by StatsBase once supported by Aqua + ) +end diff --git a/test/runtests.jl b/test/runtests.jl index 94986d240..eab7e8e76 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,7 +3,7 @@ using Dates using LinearAlgebra using Random -tests = ["ambiguous", +tests = ["aqua", "weights", "moments", "scalarstats", From 9deccb6cdbf51e43027b08c62d699428da529552 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Sat, 17 Jun 2023 15:46:59 +0200 Subject: [PATCH 3/6] Load Statistics --- test/runtests.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/runtests.jl b/test/runtests.jl index eab7e8e76..fe4828a8a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,6 +2,7 @@ using StatsBase using Dates using LinearAlgebra using Random +using Statistics tests = ["aqua", "weights", From 0fcbf361e0e166a869bd3eb7e17ed0b944811996 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Tue, 20 Jun 2023 12:46:31 +0200 Subject: [PATCH 4/6] Fix alignment --- src/statmodels.jl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/statmodels.jl b/src/statmodels.jl index b77d82e77..89ce7b99a 100644 --- a/src/statmodels.jl +++ b/src/statmodels.jl @@ -79,9 +79,18 @@ end struct TestStat v::Real end +TestStat(x::TestStat) = x show(io::IO, x::TestStat) = @printf(io, "%.2f", x.v) -TestStat(x::TestStat) = x + +# Better alignment when printing tables +# Adapted from alignment(::IO, ::Real) (https://github.com/JuliaLang/julia/blob/0da46e25c865a390b5c2de20c2d40afb41fcac0a/base/show.jl#L3022-L3027) +function Base.alignment(io::IO, x::Union{PValue,TestStat}) + s = sprint(show, x) + m = match(r"^(.*?)((?:[\.eEfF].*)?)$", s) + m === nothing ? (textwidth(s), 0) : + (textwidth(m.captures[1]), textwidth(m.captures[2])) +end """Wrap a string so that show omits quotes""" struct NoQuote From 3520205fc7f108dbd83a635a2cc1b3a9001c87bc Mon Sep 17 00:00:00 2001 From: David Widmann Date: Tue, 20 Jun 2023 13:10:43 +0200 Subject: [PATCH 5/6] Fix Aqua tests on Julia 1.0 --- test/aqua.jl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/aqua.jl b/test/aqua.jl index 8b70c96f3..b6fe6ab20 100644 --- a/test/aqua.jl +++ b/test/aqua.jl @@ -5,7 +5,12 @@ using Test @testset "Aqua" begin Aqua.test_all( StatsBase; - ambiguities=(exclude = [sort!],), # ambiguity in SortingAlgorithms (ignore) - piracy=(broken = true,), # should ignore `describe`, `pairwise`, `pairwise!` etc. which are owned by StatsBase once supported by Aqua + # Ambiguity checks error due to a bug in Aqua on older Julia versions: + # https://github.com/JuliaTesting/Aqua.jl/issues/141 + # We also ignore an ambiguity introduced by SortingAlgorithms + ambiguities=VERSION >= v"1.6" ? (exclude = [sort!],) : false, + # We should ignore `describe`, `pairwise`, `pairwise!` etc. which are owned by StatsBase once supported by Aqua: + # https://github.com/JuliaTesting/Aqua.jl/pull/140 + piracy=(broken = true,), ) end From 34ded45be72621e7fbb5eb7ec664601bb58c848b Mon Sep 17 00:00:00 2001 From: David Widmann Date: Tue, 27 Jun 2023 14:47:30 +0200 Subject: [PATCH 6/6] Fix piracy tests --- Project.toml | 2 +- test/aqua.jl | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Project.toml b/Project.toml index b1c25b8e0..7c63d7a84 100644 --- a/Project.toml +++ b/Project.toml @@ -17,7 +17,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" StatsAPI = "82ae8749-77ed-4fe6-ae5f-f523153014b0" [compat] -Aqua = "0.6.3" +Aqua = "0.6.5" DataAPI = "1" DataStructures = "0.10, 0.11, 0.12, 0.13, 0.14, 0.17, 0.18" LogExpFunctions = "0.3" diff --git a/test/aqua.jl b/test/aqua.jl index b6fe6ab20..fbddd7d60 100644 --- a/test/aqua.jl +++ b/test/aqua.jl @@ -5,12 +5,12 @@ using Test @testset "Aqua" begin Aqua.test_all( StatsBase; - # Ambiguity checks error due to a bug in Aqua on older Julia versions: - # https://github.com/JuliaTesting/Aqua.jl/issues/141 - # We also ignore an ambiguity introduced by SortingAlgorithms - ambiguities=VERSION >= v"1.6" ? (exclude = [sort!],) : false, - # We should ignore `describe`, `pairwise`, `pairwise!` etc. which are owned by StatsBase once supported by Aqua: - # https://github.com/JuliaTesting/Aqua.jl/pull/140 - piracy=(broken = true,), + # Ignore an ambiguity introduced by SortingAlgorithms + # Disable test on Julia < 1.6 due to ambiguities in ChainRulesCore + # (fixed in more recent versions not supported by Julia < 1.6) + ambiguities=VERSION < v"1.6" ? false : (exclude = [sort!],), + # `describe`, `pairwise`, `pairwise!`, and `weights` are defined in StatsAPI but owned by StasBase + # `quantile(::AbstractVector{<:Real})` is a deprecated method that should be removed + piracy=(treat_as_own = [describe, pairwise, pairwise!, weights, quantile],), ) end