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

Method __init__

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

Initialize a graph with graph, edges, name, or graph attributes Parameters ---------- incoming_graph_data : input graph (optional, default: None) Data to initialize graph. If None (default) an empty graph is created. The data can be an edge list, any

(self, incoming_graph_data=None, default_label=None, **attr)

Source from the content-addressed store, hash-verified

275 return Graph
276
277 def __init__(self, incoming_graph_data=None, default_label=None, **attr):
278 """Initialize a graph with graph, edges, name, or graph attributes
279
280 Parameters
281 ----------
282 incoming_graph_data : input graph (optional, default: None)
283 Data to initialize graph. If None (default) an empty
284 graph is created. The data can be an edge list, any
285 NetworkX graph object or any GraphScope graph object.
286 If the corresponding optional Python packages are installed
287 the data can also be a 2D NumPy array, a SciPy sparse matrix
288
289 default_label : default node label (optional, default: "_")
290 if incoming_graph_data is a GraphScope graph object, default label means
291 the nodes of the label can be accessed by id directly, other label nodes
292 need to use `(label, id)` to access.
293
294 attr : keyword arguments, optional (default= no attributes)
295 Attributes to add to graph as key=value pairs.
296
297 See Also
298 --------
299 convert
300
301 Examples
302 --------
303 >>> G = nx.Graph() # or DiGraph
304 >>> G = nx.Graph(name='my graph')
305 >>> e = [(1, 2), (2, 3), (3, 4)] # list of edges
306 >>> G = nx.Graph(e)
307
308 Arbitrary graph attribute pairs (key=value) may be assigned
309
310 >>> G = nx.Graph(e, day="Friday")
311 >>> G.graph
312 {'day': 'Friday'}
313
314 Created from a GraphScope graph object
315
316 >>> g = graphscope.g(directed=False) # if transform to DiGraph, directed=True
317 >>> g.add_vertices("person.csv", label="person").add_vertices("comment.csv", label="comment").add_edges(...)
318 >>> G = nx.Graph(g, default_label="person") # or DiGraph
319
320 """
321 self.graph_attr_dict_factory = self.graph_attr_dict_factory
322 self.node_dict_factory = self.node_dict_factory
323 self.adjlist_outer_dict_factory = self.adjlist_outer_dict_factory
324 self.cache = self.graph_cache_factory(self)
325
326 # init node and adj (must be after cache)
327 self.graph = self.graph_attr_dict_factory()
328 self._node = self.node_dict_factory(self)
329 self._adj = self.adjlist_outer_dict_factory(self)
330
331 self._key = None
332 self._op = None
333 self._schema = GraphSchema()
334

Callers

nothing calls this directly

Calls 10

_is_gs_graphMethod · 0.95
is_directedMethod · 0.95
GraphSchemaClass · 0.90
get_session_by_idFunction · 0.90
get_default_sessionFunction · 0.90
to_networkx_graphFunction · 0.90
popMethod · 0.45
warmupMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected