MCPcopy Create free account
hub / github.com/alibaba/GraphScope / to_directed

Method to_directed

python/graphscope/nx/classes/graph.py:1724–1781  ·  view source on GitHub ↗

Returns a directed representation of the graph. Parameters ---------- as_view : bool, optional (default=False) If True return a view of the original directed graph. Returns ------- G : DiGraph A directed graph with the same na

(self, as_view=False)

Source from the content-addressed store, hash-verified

1722
1723 @clear_mutation_cache
1724 def to_directed(self, as_view=False):
1725 """Returns a directed representation of the graph.
1726
1727 Parameters
1728 ----------
1729 as_view : bool, optional (default=False)
1730 If True return a view of the original directed graph.
1731
1732 Returns
1733 -------
1734 G : DiGraph
1735 A directed graph with the same name, same nodes, and with
1736 each edge (u, v, data) replaced by two directed edges
1737 (u, v, data) and (v, u, data).
1738
1739 Notes
1740 -----
1741 This by default returns a "deepcopy" of the edge, node, and
1742 graph attributes which attempts to completely copy
1743 all of the data and references.
1744
1745 Examples
1746 --------
1747 >>> G = nx.Graph()
1748 >>> G.add_edge(0, 1)
1749 >>> H = G.to_directed()
1750 >>> list(H.edges)
1751 [(0, 1), (1, 0)]
1752
1753 If already directed, return a (deep) copy
1754
1755 >>> G = nx.DiGraph()
1756 >>> G.add_edge(0, 1)
1757 >>> H = G.to_directed()
1758 >>> list(H.edges)
1759 [(0, 1)]
1760 """
1761 self._convert_arrow_to_dynamic()
1762
1763 if self.is_directed():
1764 return self.copy(as_view=as_view)
1765 graph_class = self.to_directed_class()
1766 if as_view:
1767 g = generic_graph_view(self, graph_class)
1768 g._op = self._op
1769 g._key = self._key
1770 g._session = self._session
1771 g._is_client_view = True
1772 return g
1773 g = graph_class(create_empty_in_engine=False)
1774 g.graph = copy.deepcopy(self.graph)
1775 op = dag_utils.to_directed(self)
1776 graph_def = op.eval(leaf=False)
1777 g._key = graph_def.key
1778 g._session = self._session
1779 g._op = op
1780 g.cache.warmup()
1781 return g

Callers 15

test_graph_chainMethod · 0.95
_init_product_graphFunction · 0.95
test_weight_keywordMethod · 0.95
test_disconnectedMethod · 0.95
setup_methodMethod · 0.45
test_already_directedMethod · 0.45
setup_classMethod · 0.45
test_to_directedMethod · 0.45

Calls 7

is_directedMethod · 0.95
copyMethod · 0.95
to_directed_classMethod · 0.95
generic_graph_viewFunction · 0.90
evalMethod · 0.45
warmupMethod · 0.45

Tested by 15

test_graph_chainMethod · 0.76
test_weight_keywordMethod · 0.76
test_disconnectedMethod · 0.76
setup_methodMethod · 0.36
test_already_directedMethod · 0.36
setup_classMethod · 0.36
test_to_directedMethod · 0.36