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

Function set_node_attributes

python/graphscope/nx/classes/function.py:164–188  ·  view source on GitHub ↗
(G, values, name=None)

Source from the content-addressed store, hash-verified

162
163@patch_docstring(func.set_node_attributes)
164def set_node_attributes(G, values, name=None):
165 if G.is_multigraph():
166 # multigraph forward NetworkX
167 func.set_node_attributes(G, values, name)
168 return
169
170 # Set node attributes based on type of `values`
171 if name is not None: # `values` must not be a dict of dict
172 try: # `values` is a dict
173 for n, v in values.items():
174 if n in G:
175 dd = get_node_data(G, n)
176 dd[name] = values[n]
177 G.set_node_data(n, dd)
178 except AttributeError: # `values` is a constant
179 for n in G:
180 dd = get_node_data(G, n)
181 dd[name] = values
182 G.set_node_data(n, dd)
183 else: # `values` must be dict of dict
184 for n, d in values.items():
185 if n in G:
186 dd = get_node_data(G, n)
187 dd.update(d)
188 G.set_node_data(n, dd)
189
190
191@patch_docstring(func.set_edge_attributes)

Callers

nothing calls this directly

Calls 5

get_node_dataFunction · 0.90
itemsMethod · 0.80
set_node_dataMethod · 0.80
is_multigraphMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected