code: def assert_indexing_works(
      X: DatasetLike,
      idx: Optional[List[int]] = None,
      length_X: Optional[int] = None,
  ) -> None:
      """Ensures we can do list-based indexing into ``X`` and ``y``.
      ``length_X`` is an optional argument since sparse matrix ``X``
      does not support: ``len(X)`` and we want this method to work for sparse ``X``
      (in addition to many other types of ``X``).
      """
      if idx is None:
          if length_X is None:
              length_X = 2  # pragma: no cover
  
          idx = [0, length_X - 1]
  
      is_indexed = False
      try:
          if isinstance(X, (pd.DataFrame, pd.Series)):
              _ = X.iloc[idx]  # type: ignore[call-overload]
              is_indexed = True
      except Exception:
          pass
      if not is_indexed:
          try:  # check if X is pytorch Dataset object using lazy import
              import torch
  
              if isinstance(
                  X, torch.utils.data.Dataset
              ):  # indexing for pytorch Dataset
                  _ = torch.utils.data.Subset(X, idx)  # type: ignore[call-overload]
                  is_indexed = True
          except Exception:
              pass
      if not is_indexed:
          try:  # check if X is tensorflow Dataset object using lazy import
              import tensorflow as tf
  
              if isinstance(X, tf.data.Dataset):
                  is_indexed = True  # skip check for tensorflow Dataset (too expensive)
          except Exception:
              pass
      if not is_indexed:
          try:
              _ = X[idx]  # type: ignore[call-overload]
          except Exception:
              msg = "Data features X must support list-based indexing; i.e. one of these must work: \n"
              msg += "1)  X[index_list] where say index_list = [0,1,3,10], or \n"
              msg += "2)  X.iloc[index_list] if X is pandas DataFrame."
              raise TypeError(msg)
  
file_path: cleanlab/cleanlab/internal/validation.py
imports: from cleanlab.typing import LabelLike, DatasetLike
  from cleanlab.internal.constants import FLOATING_POINT_COMPARISON
  from typing import Any, List, Optional, Union
  import warnings
  import numpy
  import pandas
label_desc: Use image node_id 4 for calling a global function with example usage: assert_indexing_works(X, idx, length_X) without return types