code: def weakly_connected_components(
      G, directed=None, connection=None, return_labels=None
  ):
      """
      Generate the Weakly Connected Components and attach a component label to
      each vertex.
  
      Parameters
      ----------
      G : cugraph.Graph, networkx.Graph, CuPy or SciPy sparse matrix
  
          Graph or matrix object, which should contain the connectivity
          information (edge weights are not used for this algorithm). If using a
          graph object, the graph must be undirected where an
          undirected edge is represented by a directed edge in both directions.
          The adjacency list will be computed if not already present. The number
          of vertices should fit into a 32b int.
  
      directed : bool, optional (default=None)
  
          NOTE
              For non-Graph-type (eg. sparse matrix) values of G only.
              Raises TypeError if used with a Graph object.
  
          If True, then convert the input matrix to a Graph(directed=True)
          and only move from point i to point j along paths csgraph[i, j]. If
          False, then find the shortest path on an undirected graph: the
          algorithm can progress from point i to j along csgraph[i, j] or
          csgraph[j, i].
  
      connection : str, optional (default=None)
  
          Added for SciPy compatibility, can only be specified for non-Graph-type
          (eg. sparse matrix) values of G only (raises TypeError if used with a
          Graph object), and can only be set to "weak" for this API.
  
      return_labels : bool, optional (default=True)
  
          NOTE
              For non-Graph-type (eg. sparse matrix) values of G only. Raises
              TypeError if used with a Graph object.
  
          If True, then return the labels for each of the connected
          components.
  
      Returns
      -------
      Return value type is based on the input type.  If G is a cugraph.Graph,
      returns:
  
         cudf.DataFrame
             GPU data frame containing two cudf.Series of size V: the vertex
             identifiers and the corresponding component identifier.
  
             df['vertex']
                 Contains the vertex identifier
             df['labels']
                 The component identifier
  
      If G is a networkx.Graph, returns:
  
         python dictionary, where keys are vertices and values are the component
         identifiers.
  
      If G is a CuPy or SciPy matrix, returns:
  
         CuPy ndarray (if CuPy matrix input) or Numpy ndarray (if SciPy matrix
         input) of shape (<num vertices>, 2), where column 0 contains component
         identifiers and column 1 contains vertices.
  
      Examples
      --------
      >>> from cugraph.datasets import karate
      >>> G = karate.get_graph(download=True)
      >>> df = cugraph.weakly_connected_components(G)
  
      """
      (directed, connection, return_labels) = _ensure_args(
          "weakly_connected_components",
          G,
          directed,
          connection,
          return_labels,
      )
  
      # FIXME: allow nx_weight_attr to be specified
      (G, input_type) = ensure_cugraph_obj(
          G,
          nx_weight_attr="weight",
          matrix_graph_type=Graph(directed=directed),
      )
  
      if G.is_directed():
          raise ValueError("input graph must be undirected")
  
      vertex, labels = pylibcugraph_wcc(
          resource_handle=ResourceHandle(),
          graph=G._plc_graph,
          offsets=None,
          indices=None,
          weights=None,
          labels=None,
          do_expensive_check=False,
      )
  
      df = cudf.DataFrame()
      df["vertex"] = vertex
      df["labels"] = labels
  
      if G.renumbered:
          df = G.unrenumber(df, "vertex")
  
      return _convert_df_to_output_type(df, input_type, return_labels)
  
file_path: cugraph/python/cugraph/cugraph/components/connectivity.py
imports: from cugraph.utilities import df_score_to_dictionary, ensure_cugraph_obj, is_matrix_type, is_cp_matrix_type, is_nx_graph_type, cupy_package
  from cugraph.structure import Graph
  from cugraph.components import connectivity_wrapper
  import cudf
  from pylibcugraph import weakly_connected_components
  from pylibcugraph import ResourceHandle
label_desc: Use image node_id 3 for calling a global function with example usage: weakly_connected_components(G, directed, connection, return_labels) and returns: _convert_df_to_output_type