From f1932fb1e1747058f60acb608504fbff3dccd951 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Fri, 16 Dec 2022 14:25:12 -0500 Subject: [PATCH] 19566: Silence logging from glm library. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- glm_test.go | 14 ++++++++++++++ slicenumpy.go | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/glm_test.go b/glm_test.go index 62c907f55e..ec3c000f95 100644 --- a/glm_test.go +++ b/glm_test.go @@ -276,6 +276,20 @@ func (s *glmSuite) TestPvalue(c *check.C) { 1, 1, 3, 1.21, 2.31 `) c.Check(glmPvalueFunc(samples, npca)(onehot), check.Equals, 0.002789665435066107) + + samples, onehot, npca = csv2test(` +# case=1, onehot=1, pca1, pca2, pca3 +0, 1, 1, 1.21, 2.37 +0, 1, 2, 1.22, 2.38 +0, 1, 3, 1.23, 2.39 +0, 1, 1, 1.24, 2.33 +0, 1, 2, 1.25, 2.34 +1, 1, 3, 1.26, 2.35 +1, 1, 1, 1.23, 2.36 +1, 1, 2, 1.22, 2.32 +1, 1, 3, 1.21, 2.31 +`) + c.Check(math.IsNaN(glmPvalueFunc(samples, npca)(onehot)), check.Equals, true) } var benchSamples, benchOnehot = func() ([]sampleInfo, []bool) { diff --git a/slicenumpy.go b/slicenumpy.go index e4dd766c84..84d501b5c6 100644 --- a/slicenumpy.go +++ b/slicenumpy.go @@ -190,6 +190,18 @@ func (cmd *sliceNumpy) run(prog string, args []string, stdin io.Reader, stdout, } if len(cmd.samples[0].pcaComponents) > 0 { cmd.pvalue = glmPvalueFunc(cmd.samples, cmd.pcaComponents) + // Unfortunately, statsmodel/glm lib logs + // stuff to os.Stdout when it panics on an + // unsolvable problem. We recover() from the + // panic in glm.go, but we also need to + // commandeer os.Stdout to avoid producing + // large quantities of logs. + stdoutWas := os.Stdout + defer func() { os.Stdout = stdoutWas }() + os.Stdout, err = os.Open(os.DevNull) + if err != nil { + return err + } } } else if *caseControlOnly { return fmt.Errorf("-case-control-only does not make sense without -samples") -- 2.30.2