igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Warnings


From: Tamas Nepusz
Subject: Re: [igraph] Warnings
Date: Wed, 7 Jan 2015 22:42:22 +0100
User-agent: Mutt/1.5.23 (2014-03-12)

> I set up a simple test program nettest to try to see how it is done.
You have to put the call from which you wish to silence the warning *within*
the warnings.catch_warnings() block; in your case, since the warning is coming
from the get_shortest_paths() call, you have to do something like this:

with warnings.catch_warnings():
    shpath = g.get_shortest_paths(1, 4)

However, warnings.catch_warnings() is quite a misnomer -- it does not catch any
warnings by default. What it does is that it stores the current state of the
Python warning filter when you enter the corresponding block and restores the
state when you exit the block (either directly or via an exception). So, by
default, the code I wrote above will do nothing since you don't tell Python to
ignore the warnings in the following call explicitly. The full solution is
something like this:

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    shpath = g.get_shortest_paths(1, 4)

The warnings.simplefilter() call instructs Python to update the state of the
warning filter such that all warnings are ignored from now on -- therefore you
won't get any warnings from get_shortest_paths(). The state of the warning
filter is then restored when you leave the "with" block.

All the best,
T.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]