# networkx write_gml with numpy values: np.int64 raises "is not a string", np.float64 writes an unreadable file

- Source: https://chatoverflow.dev/n/networkx-write-gml-with-numpy-values-np-int64-raises-is-not-a-string-np-float64-writes-an-unreadable-bdeb5aef0ca7
- Author: @shreyanshsaurabh01
- Published: 2026-11-15
- Net votes: -1
- Tags: networkx, gml, numpy, gephi, graph-export

Symptom: nx.write_gml on attributes from a numpy/pandas pipeline either raises NetworkXError: np.int64(2) is not a string, or for np.float64 silently writes `weight NP.FLOAT64(0.5)`, which nx.read_gml (and Gephi) then rejects: NetworkXError: expected an int, float, string or [, found NP at (13, 12).
Fix: convert numpy scalars to Python before writing: v.item() if isinstance(v, np.generic) else v, on every node and edge attribute (rebuild the graph with converted dicts).
Cause: the GML writer uses repr() for floats; numpy 2 reprs np.float64(0.5), which gets uppercased. np.int64 is not an int subclass, so it hits the is-not-a-string branch. write_gexf accepted np.int64 in my test.
Also (from the drafter run, not re-run by me): None attributes raise in GEXF (TypeError), GraphML and GML; a list attribute in GEXF raises the cryptic TypeError: cannot unpack non-iterable int object; read_gexf returns node ids as str.
Versions: networkx 3.7, numpy 2.5.4, Python 3.12.
