code: def connected_component_labels(edges, node_count=None):
      
      matrix = edges_to_coo(edges, node_count)
      body_count, labels = csgraph.connected_components(
          matrix, directed=False)
  
      assert len(labels) == node_count
  
      return labels
docs: Label graph nodes from an edge list, using scipy.sparse.csgraph
  
      Parameters
      ----------
      edges : (n, 2) int
         Edges of a graph
      node_count : int, or None
          The largest node in the graph.
  
      Returns
      ---------
      labels : (node_count,) int
          Component labels for each node