(G, values, name=None)
| 162 | |
| 163 | @patch_docstring(func.set_node_attributes) |
| 164 | def 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) |
nothing calls this directly
no test coverage detected