19566: Silence logging from glm library. 19566-glm
authorTom Clegg <tom@curii.com>
Fri, 16 Dec 2022 19:25:12 +0000 (14:25 -0500)
committerTom Clegg <tom@curii.com>
Fri, 16 Dec 2022 19:25:12 +0000 (14:25 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

glm_test.go
slicenumpy.go

index 62c907f55e656c127ce4573578688f5402a0c660..ec3c000f9594d51c60ea4fdd2783f69a072b287b 100644 (file)
@@ -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) {
index e4dd766c84586ea691161cc57c0ea1498bf83592..84d501b5c687114309be59a4e1211980265a11a3 100644 (file)
@@ -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")