code: def _num_samples(x):
      """Return number of samples in array-like x"""
      if hasattr(x, "fit") and callable(x.fit):
          # Don't get num_samples from an ensembles length!
          raise TypeError(
              "Expected sequence or array-like, got " "estimator %s" % x
          )
      if not hasattr(x, "__len__") and not hasattr(x, "shape"):
          if hasattr(x, "__array__"):
              x = np.asarray(x)
          else:
              raise TypeError(
                  "Expected sequence or array-like, got %s" % type(x)
              )
      if hasattr(x, "shape"):
          if len(x.shape) == 0:
              raise TypeError(
                  "Singleton array %r cannot be considered"
                  " a valid collection." % x
              )
          # Check that shape is returning an integer or default to len
          # Dask dataframes may not return numeric shape[0] value
          if isinstance(x.shape[0], numbers.Integral):
              return x.shape[0]
          else:
              return len(x)
      else:
          return len(x)
  
file_path: sk-dist/skdist/distribute/utils.py
imports: import numbers
  import numpy
  from sklearn.metrics import check_scoring
  from .validation import _safe_indexing
label_desc: Use image node_id 5 for calling a global function with example usage: _num_samples(x) and returns: len, x, len