Skip to content

Commit 1c3f3d7

Browse files
authored
Add a no-op PValue(::PValue) constructor (#612)
`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.
1 parent c5328b1 commit 1c3f3d7

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/statmodels.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ struct PValue
431431
new(v)
432432
end
433433
end
434+
PValue(p::PValue) = p
434435

435436
function show(io::IO, pv::PValue)
436437
v = pv.v

test/statmodels.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using StatsBase
2+
using StatsBase: PValue
23
using Test, Random
34

45
v1 = [1.45666, -23.14, 1.56734e-13]
@@ -28,16 +29,17 @@ m = rand(3,4)
2829
[3] 0.344454 0.179574 0.242208 0.4531
2930
──────────────────────────────────────────"""
3031

31-
@test sprint(show, StatsBase.PValue(1.0)) == "1.0000"
32-
@test sprint(show, StatsBase.PValue(1e-1)) == "0.1000"
32+
@test sprint(show, PValue(1.0)) == "1.0000"
33+
@test sprint(show, PValue(1e-1)) == "0.1000"
3334
if VERSION > v"1.6.0-DEV"
34-
@test sprint(show, StatsBase.PValue(1e-5)) == "<1e-04"
35+
@test sprint(show, PValue(1e-5)) == "<1e-04"
3536
else
36-
@test sprint(show, StatsBase.PValue(1e-5)) == "<1e-4"
37+
@test sprint(show, PValue(1e-5)) == "<1e-4"
3738
end
38-
@test sprint(show, StatsBase.PValue(NaN)) == "NaN"
39-
@test_throws ErrorException StatsBase.PValue(-0.1)
40-
@test_throws ErrorException StatsBase.PValue(1.1)
39+
@test sprint(show, PValue(NaN)) == "NaN"
40+
@test_throws ErrorException PValue(-0.1)
41+
@test_throws ErrorException PValue(1.1)
42+
@test PValue(PValue(0.05)) === PValue(0.05)
4143

4244
@test sprint(showerror, ConvergenceException(10)) == "failure to converge after 10 iterations."
4345

0 commit comments

Comments
 (0)