From a0310c393f2d7fd98f81f66f463c263245bb0bfd Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Thu, 22 Oct 2020 15:40:29 -0700 Subject: [PATCH 1/2] Add a no-op PValue(::PValue) constructor `show(::CoefTable)` calls `PValue` on all values in the p-value column (if present). If things are constructed manually and you happen to already have your p-values as `PValue`s, printing the table will fail. It seems sort of silly to have this kind of definition, but it's nice to not get errors when trying to look at your `CoefTable` in the REPL. --- src/statmodels.jl | 1 + test/statmodels.jl | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/statmodels.jl b/src/statmodels.jl index 3536e3c98..08ce24730 100644 --- a/src/statmodels.jl +++ b/src/statmodels.jl @@ -431,6 +431,7 @@ struct PValue new(v) end end +PValue(p::PValue) = p function show(io::IO, pv::PValue) v = pv.v diff --git a/test/statmodels.jl b/test/statmodels.jl index 5d0e93de5..197876659 100644 --- a/test/statmodels.jl +++ b/test/statmodels.jl @@ -1,4 +1,5 @@ using StatsBase +using StatsBase: PValue using Test, Random v1 = [1.45666, -23.14, 1.56734e-13] @@ -28,16 +29,17 @@ m = rand(3,4) [3] 0.344454 0.179574 0.242208 0.4531 ──────────────────────────────────────────""" -@test sprint(show, StatsBase.PValue(1.0)) == "1.0000" -@test sprint(show, StatsBase.PValue(1e-1)) == "0.1000" +@test sprint(show, PValue(1.0)) == "1.0000" +@test sprint(show, PValue(1e-1)) == "0.1000" if VERSION > v"1.6.0-DEV" - @test sprint(show, StatsBase.PValue(1e-5)) == "<1e-04" + @test sprint(show, PValue(1e-5)) == "<1e-04" else - @test sprint(show, StatsBase.PValue(1e-5)) == "<1e-4" + @test sprint(show, PValue(1e-5)) == "<1e-4" end -@test sprint(show, StatsBase.PValue(NaN)) == "NaN" -@test_throws ErrorException StatsBase.PValue(-0.1) -@test_throws ErrorException StatsBase.PValue(1.1) +@test sprint(show, PValue(NaN)) == "NaN" +@test_throws ErrorException PValue(-0.1) +@test_throws ErrorException PValue(1.1) +@test PValue(PValue(PValue(0.05))) == PValue(0.05) @test sprint(showerror, ConvergenceException(10)) == "failure to converge after 10 iterations." From 239e913c0a16c1cd8881d42ebd298e26d15c3495 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Fri, 23 Oct 2020 11:27:35 -0700 Subject: [PATCH 2/2] Extra =s for that fresh, egal taste Co-authored-by: Milan Bouchet-Valat --- test/statmodels.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/statmodels.jl b/test/statmodels.jl index 197876659..632d861ac 100644 --- a/test/statmodels.jl +++ b/test/statmodels.jl @@ -39,7 +39,7 @@ end @test sprint(show, PValue(NaN)) == "NaN" @test_throws ErrorException PValue(-0.1) @test_throws ErrorException PValue(1.1) -@test PValue(PValue(PValue(0.05))) == PValue(0.05) +@test PValue(PValue(0.05)) === PValue(0.05) @test sprint(showerror, ConvergenceException(10)) == "failure to converge after 10 iterations."