|
From: | Gábor Csárdi |
Subject: | Re: [igraph] Suggestion? |
Date: | Wed, 14 Jan 2015 16:17:46 -0500 |
Hi,
> There is an ambiguity. You get the same warning if the two nodes are the
> same.
So I've tested this a little bit and here is how it works right now. First
I set up a simple test graph:
>>> g = Graph.Formula("A --> B -->C")
Then let's see what happens when I call get_shortest_paths() with two nodes for
which there exists a path:
>>> g.get_shortest_paths("A", "C")
[[0, 1, 2]]
Calling get_shortest_paths() with two nodes without a corresponding path yields
a warning (which you can suppress) AND you get the empty list as a result:
>>> g.get_shortest_paths("C", "A")
/Users/ntamas/.pyenv/versions/default-venv/bin/igraph:1: RuntimeWarning:
Couldn't reach some vertices at ../../src/structural_properties.c:740
[[]]
So, the result includes the empty list that you proposed as a logical outcome
-- the only thing that could be confusing is the warning. (Also, if you happen
to have configured Python to turn all warnings into exceptions, then you have
a problem here because you won't get the empty list, but as far as I know this
is not the default in Python).
Finally, this is what happens when you call get_shortest_paths() with the same
node:
>>> g.get_shortest_paths("A", "A")
[[0]]
I think this is correct even though "A" does not have a loop edge since you
are already "at" node A when you start the walk.
Let's ignore the warnings for the time being; my question is: do you have any
objections against the *results* of the above calls or do you think it's
logical this way?
Going back to the warnings: my personal opinion is that I don't like them
either, and I also suspect that the warning is there only because it is more
common in R to print warnings for conditions like this, and Gabor found it more
logical in the early days to implement such a warning in the C layer. The only
easy thing I can do about it in the Python layer is to add a function called
set_warning_handler() (similarly to set_progress_handler() and
set_status_handler(), which are used to draw progress bars for certain
operations in IPython). set_warning_handler() would allow you to specify
a Python function that handles warnings coming from the C layer. The default
warning handler would be the same as what we have now: it will convert the
igraph warning into a Python warning. However, you could then be able to call
set_warning_handler(None) to suppress any warnings coming from igraph while
still keeping warnings coming from any other part of Python.
All the best,
T.
_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help
[Prev in Thread] | Current Thread | [Next in Thread] |