**diff options**

author | Nathann Cohen <nathann.cohen@gmail.com> | 2015-07-27 15:51:49 +0200 |
---|---|---|

committer | Michele Borassi <michele.borassi@imtlucca.it> | 2015-07-28 12:42:54 +0200 |

commit | 36f998a1492a46428c0cdfec4fa9084dcbe27e5e (patch) | |

tree | eb27a4a528bdd7d430d2a0a43c118eceabd65539 | |

parent | Solved a problem with isolated vertices (diff) |

trac #18929: Reviewer's commit

-rw-r--r-- | src/sage/graphs/digraph.py | 13 | ||||

-rw-r--r-- | src/sage/graphs/graph.py | 14 |

2 files changed, 19 insertions, 8 deletions

diff --git a/src/sage/graphs/digraph.py b/src/sage/graphs/digraph.py index e3fefcc..4af5254 100644 --- a/src/sage/graphs/digraph.py +++ b/src/sage/graphs/digraph.py @@ -632,12 +632,17 @@ class DiGraph(GenericGraph): format = 'NX' elif isinstance(data, (networkx.DiGraph, networkx.MultiDiGraph)): format = 'NX' - try: - import igraph + if (format is None and + hasattr(data, 'vcount') and + hasattr(data, 'get_edgelist')): + try: + import igraph + except ImportError: + raise ImportError("The data seems to be a igraph object, but "+ + "igraph is not installed in Sage. To install "+ + "it, run 'sage -i python_igraph'") if format is None and isinstance(data, igraph.Graph): format = 'igraph' - except ImportError: - pass if format is None and isinstance(data, (int, Integer)): format = 'int' if format is None and data is None: diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py index 86c82af..08be7ec 100644 --- a/src/sage/graphs/graph.py +++ b/src/sage/graphs/graph.py @@ -1177,12 +1177,18 @@ class Graph(GenericGraph): data = data.to_undirected() elif isinstance(data, (networkx.Graph, networkx.MultiGraph)): format = 'NX' - try: - import igraph + + if (format is None and + hasattr(data, 'vcount') and + hasattr(data, 'get_edgelist')): + try: + import igraph + except ImportError: + raise ImportError("The data seems to be a igraph object, but "+ + "igraph is not installed in Sage. To install "+ + "it, run 'sage -i python_igraph'") if format is None and isinstance(data, igraph.Graph): format = 'igraph' - except ImportError: - pass if format is None and isinstance(data, (int, Integer)): format = 'int' if format is None and data is None: |