code: def test_special_float_label(self, tmp_path):
      special_floats = [float("nan"), float("+inf"), float("-inf")]
      try:
          import numpy as np
  
          special_floats += [np.nan, np.inf, np.inf * -1]
      except ImportError:
          special_floats += special_floats
  
      G = nx.cycle_graph(len(special_floats))
      attrs = dict(enumerate(special_floats))
      nx.set_node_attributes(G, attrs, "nodefloat")
      edges = list(G.edges)
      attrs = {
          edges[i]: value for i, value in enumerate(special_floats)
      }
      nx.set_edge_attributes(G, attrs, "edgefloat")
  
      with open(tmp_path / "test.gml", "w+b") as fobj:
          nx.write_gml(G, fobj)
          fobj.seek(0)
          # Should be bytes in 2.x and 3.x
          data = fobj.read().strip().decode("ascii")
          answer = """graph [
    node [
      id 0
      label "0"
      nodefloat NAN
    ]
    node [
      id 1
      label "1"
      nodefloat +INF
    ]
    node [
      id 2
      label "2"
      nodefloat -INF
    ]
    node [
      id 3
      label "3"
      nodefloat NAN
    ]
    node [
      id 4
      label "4"
      nodefloat +INF
    ]
    node [
      id 5
      label "5"
      nodefloat -INF
    ]
    edge [
      source 0
      target 1
      edgefloat NAN
    ]
    edge [
      source 0
      target 5
      edgefloat +INF
    ]
    edge [
      source 1
      target 2
      edgefloat -INF
    ]
    edge [
      source 2
      target 3
      edgefloat NAN
    ]
    edge [
      source 3
      target 4
      edgefloat +INF
    ]
    edge [
      source 4
      target 5
      edgefloat -INF
    ]
  ]"""
          assert data == answer
  
          fobj.seek(0)
          graph = nx.read_gml(fobj)
          for indx, value in enumerate(special_floats):
              node_value = graph.nodes[str(indx)]["nodefloat"]
              if math.isnan(value):
                  assert math.isnan(node_value)
              else:
                  assert node_value == value
  
              edge = edges[indx]
              string_edge = (str(edge[0]), str(edge[1]))
              edge_value = graph.edges[string_edge]["edgefloat"]
              if math.isnan(value):
                  assert math.isnan(edge_value)
              else:
                  assert edge_value == value
  
imports: import codecs
  import io
  import math
  from ast import literal_eval
  from contextlib import contextmanager
  from textwrap import dedent
  import pytest
  import networkx
  from networkx.readwrite.gml import literal_destringizer, literal_stringizer
label_desc: Use image node_id 11 for calling the TestGraph obj's underlying member method code with example usage: obj.test_special_float_label(tmp_path) without return types