class_docstr: Manages data sample with low valuation.
class_docstr_tok: ["Manages","data","sample","with","low","valuation","."]
docstr: Determine if a knn_graph is provided in the kwargs or if one is already stored in the associated Datalab instance.
docstr_tok: ["Determine","if","a","knn_graph","is","provided","in","the","kwargs","or","if","one","is","already","stored","in","the","associated","Datalab","instance","."]
code: def _process_knn_graph_from_inputs(
      self, kwargs: Dict[str, Any]
  ) -> Union[csr_matrix, None]:
      """Determine if a knn_graph is provided in the kwargs or if one is already stored in the associated Datalab instance."""
      knn_graph_kwargs: Optional[csr_matrix] = kwargs.get(
          "knn_graph", None
      )
      knn_graph_stats = self.datalab.get_info("statistics").get(
          "weighted_knn_graph", None
      )
  
      knn_graph: Optional[csr_matrix] = None
      if knn_graph_kwargs is not None:
          knn_graph = knn_graph_kwargs
      elif knn_graph_stats is not None:
          knn_graph = knn_graph_stats
  
      if isinstance(knn_graph, csr_matrix) and kwargs.get("k", 0) > (
          knn_graph.nnz // knn_graph.shape[0]
      ):
          # If the provided knn graph is insufficient, then we need to recompute the knn graph
          # with the provided features
          knn_graph = None
      return knn_graph
  
file_path: cleanlab/cleanlab/datalab/internal/issue_manager/data_valuation.py
imports: from __future__ import annotations
  from typing import TYPE_CHECKING, Any, ClassVar, Dict, List, Optional, Union
  import numpy
  import pandas
  from scipy.sparse import csr_matrix
  from cleanlab.datalab.internal.issue_manager import IssueManager
label_desc: Use image node_id 3 for calling the DataValuationIssueManager obj's underlying member method code with example usage: obj._process_knn_graph_from_inputs(kwargs) and returns: knn_graph