MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / write_graphml_lxml

Function write_graphml_lxml

easygraph/readwrite/graphml.py:122–190  ·  view source on GitHub ↗

Write G in GraphML XML format to path This function uses the LXML framework and should be faster than the version using the xml library. Parameters ---------- G : graph A easygraph graph path : file or string File or filename to write. Filenames ending

(
    G,
    path,
    encoding="utf-8",
    prettyprint=True,
    infer_numeric_types=False,
    named_key_ids=False,
    edge_id_from_attribute=None,
)

Source from the content-addressed store, hash-verified

120
121@open_file(1, mode="wb")
122def write_graphml_lxml(
123 G,
124 path,
125 encoding="utf-8",
126 prettyprint=True,
127 infer_numeric_types=False,
128 named_key_ids=False,
129 edge_id_from_attribute=None,
130):
131 """Write G in GraphML XML format to path
132
133 This function uses the LXML framework and should be faster than
134 the version using the xml library.
135
136 Parameters
137 ----------
138 G : graph
139 A easygraph graph
140 path : file or string
141 File or filename to write.
142 Filenames ending in .gz or .bz2 will be compressed.
143 encoding : string (optional)
144 Encoding for text data.
145 prettyprint : bool (optional)
146 If True use line breaks and indenting in output XML.
147 infer_numeric_types : boolean
148 Determine if numeric types should be generalized.
149 For example, if edges have both int and float 'weight' attributes,
150 we infer in GraphML that both are floats.
151 named_key_ids : bool (optional)
152 If True use attr.name as value for key elements' id attribute.
153 edge_id_from_attribute : dict key (optional)
154 If provided, the graphml edge id is set by looking up the corresponding
155 edge data attribute keyed by this parameter. If `None` or the key does not exist in edge data,
156 the edge id is set by the edge key if `G` is a MultiGraph, else the edge id is left unset.
157
158 Examples
159 --------
160 >>> G = eg.path_graph(4)
161 >>> eg.write_graphml_lxml(G, "fourpath.graphml")
162
163 Notes
164 -----
165 This implementation does not support mixed graphs (directed
166 and unidirected edges together) hyperedges, nested graphs, or ports.
167 """
168 try:
169 import lxml.etree as lxmletree
170 except ImportError:
171 return write_graphml_xml(
172 G,
173 path,
174 encoding,
175 prettyprint,
176 infer_numeric_types,
177 named_key_ids,
178 edge_id_from_attribute,
179 )

Callers

nothing calls this directly

Calls 3

dumpMethod · 0.95
write_graphml_xmlFunction · 0.85
GraphMLWriterLxmlClass · 0.85

Tested by

no test coverage detected