anilbey
anilbey

Reputation: 1977

Snakemake how to ignore a RuntimeWarning?

Unlike the default Python behaviour, Snakemake is stopping execution upon a RuntimeWarnings thrown by numpy.

/a-path/site-packages/numpy/lib/function_base.py:3250: RuntimeWarning: All-NaN slice encountered
Exiting because a job execution failed. Look above for error message


Configuring numpy.seterr using the code below does not help.

import numpy as np
np.seterr(all='print')

How can I simply tell snakemake not to terminate the rule for warnings?

Note: I am using the run: option in snakemake for the rule that is throwing the RuntimeWarning.

Upvotes: 1

Views: 579

Answers (1)

dariober
dariober

Reputation: 9062

Maybe you have an actual error somewhere else. On 5.4.2, the warnings seem ok:

rule all:
    input:
        'foo.txt',

rule one:
    output:
        touch('foo.txt'),
    run:
        import numpy as np
        np.nanmax([np.nan, np.nan])

Execution:

snakemake

Building DAG of jobs...
Using shell: /bin/bash
Provided cores: 1
Rules claiming more threads will be scaled down.
Job counts:
    count   jobs
    1   all
    1   one
    2

[Tue Jun 11 21:09:47 2019]
rule one:
    output: foo.txt
    jobid: 1

Job counts:
    count   jobs
    1   one
    1
/home/dario/miniconda3/lib/python3.6/site-packages/snakemake/workflow.py:19: RuntimeWarning: All-NaN axis encountered
  from snakemake.logging import logger, format_resources, format_resource_names
Touching output file foo.txt.
[Tue Jun 11 21:09:47 2019]
Finished job 1.
1 of 2 steps (50%) done

[Tue Jun 11 21:09:47 2019]
localrule all:
    input: foo.txt
    jobid: 0

[Tue Jun 11 21:09:47 2019]
Finished job 0.
2 of 2 steps (100%) done
Complete log: /home/dario/Tritume/.snakemake/log/2019-06-11T210947.007675.snakemake.log

In any case, you can silence errors with

import warnings
warnings.filterwarnings('ignore')

Upvotes: 1

Related Questions