code: def test_fix_connected_components_precomputed():
      # Test that _fix_connected_components accepts precomputed distance matrix.
      X = np.array([0, 1, 2, 5, 6, 7])[:, None]
      graph = kneighbors_graph(X, n_neighbors=2, mode="distance")
  
      n_connected_components, labels = connected_components(graph)
      assert n_connected_components > 1
  
      distances = pairwise_distances(X)
      graph = _fix_connected_components(
          distances,
          graph,
          n_connected_components,
          labels,
          metric="precomputed",
      )
  
      n_connected_components, labels = connected_components(graph)
      assert n_connected_components == 1
  
      # but it does not work with precomputed neighbors graph
      with pytest.raises(
          RuntimeError, match="does not work with a sparse"
      ):
          _fix_connected_components(
              graph,
              graph,
              n_connected_components,
              labels,
              metric="precomputed",
          )
  
file_path: scikit-learn/sklearn/utils/tests/test_graph.py
imports: import numpy
  import pytest
  from scipy.sparse.csgraph import connected_components
  from sklearn.metrics.pairwise import pairwise_distances
  from sklearn.neighbors import kneighbors_graph
  from sklearn.utils.graph import _fix_connected_components
label_desc: Use image node_id 2 for calling a global function with example usage: test_fix_connected_components_precomputed() without return types