code: def partition_spanning_tree(
      G,
      minimum=True,
      weight="weight",
      partition="partition",
      ignore_nan=False,
  ):
      """
      Find a spanning tree while respecting a partition of edges.
  
      Edges can be flagged as either `INCLUDED` which are required to be in the
      returned tree, `EXCLUDED`, which cannot be in the returned tree and `OPEN`.
  
      This is used in the SpanningTreeIterator to create new partitions following
      the algorithm of Sörensen and Janssens [1]_.
  
      Parameters
      ----------
      G : undirected graph
          An undirected graph.
  
      minimum : bool (default: True)
          Determines whether the returned tree is the minimum spanning tree of
          the partition of the maximum one.
  
      weight : str
          Data key to use for edge weights.
  
      partition : str
          The key for the edge attribute containing the partition
          data on the graph. Edges can be included, excluded or open using the
          `EdgePartition` enum.
  
      ignore_nan : bool (default: False)
          If a NaN is found as an edge weight normally an exception is raised.
          If `ignore_nan is True` then that edge is ignored instead.
  
  
      Returns
      -------
      G : NetworkX Graph
          A minimum spanning tree using all of the included edges in the graph and
          none of the excluded edges.
  
      References
      ----------
      .. [1] G.K. Janssens, K. Sörensen, An algorithm to generate all spanning
             trees in order of increasing cost, Pesquisa Operacional, 2005-08,
             Vol. 25 (2), p. 219-229,
             https://www.scielo.br/j/pope/a/XHswBwRwJyrfL88dmMwYNWp/?lang=en
      """
      edges = kruskal_mst_edges(
          G,
          minimum,
          weight,
          keys=True,
          data=True,
          ignore_nan=ignore_nan,
          partition=partition,
      )
      T = G.__class__()  # Same graph class as G
      T.graph.update(G.graph)
      T.add_nodes_from(G.nodes.items())
      T.add_edges_from(edges)
      return T
  
imports: from dataclasses import dataclass, field
  from enum import Enum
  from heapq import heappop, heappush
  from itertools import count
  from math import isnan
  from operator import itemgetter
  from queue import PriorityQueue
  import networkx
  from networkx.utils import UnionFind, not_implemented_for, py_random_state
label_desc: Use image node_id 7 for calling a global function with example usage: partition_spanning_tree(G, minimum, weight, partition, ignore_nan) and returns: T