code: def nx_graph_from_dataset(dataset_obj):
      """
      Read the dataset specified by the dataset_obj and create and return a
      nx.Graph or nx.DiGraph instance based on the dataset is_directed metadata.
      """
      create_using = (
          nx.DiGraph
          if dataset_obj.metadata["is_directed"]
          else nx.Graph
      )
      names = dataset_obj.metadata["col_names"]
      dtypes = dataset_obj.metadata["col_types"]
      if isinstance(dataset_obj.metadata["header"], int):
          header = dataset_obj.metadata["header"]
      else:
          header = None
  
      pandas_edgelist = pd.read_csv(
          dataset_obj.get_path(),
          delimiter=dataset_obj.metadata["delim"],
          names=names,
          dtype=dict(zip(names, dtypes)),
          header=header,
      )
      G = nx.from_pandas_edgelist(
          pandas_edgelist,
          source=names[0],
          target=names[1],
          create_using=create_using,
      )
      return G
  
imports: import random
  import networkx
  import pandas
  import pytest
  from cugraph import datasets
  import nx_cugraph
label_desc: Use image node_id 4 for calling a global function with example usage: nx_graph_from_dataset(dataset_obj) and returns: G