code: def ndloc(cls, dataset, indices):
      kdims = [d for d in dataset.kdims[::-1]]
      adjusted_indices = []
      slice_dims = []
      for kd, ind in zip(kdims, indices):
          if cls.irregular(dataset, kd):
              coords = [
                  c
                  for c in dataset.data.coords
                  if c not in dataset.data.dims
              ]
              dim = dataset.data[kd.name].dims[coords.index(kd.name)]
              shape = dataset.data[kd.name].shape[coords.index(kd.name)]
              coords = np.arange(shape)
          else:
              coords = cls.coords(dataset, kd, False)
              dim = kd.name
          slice_dims.append(dim)
          ncoords = len(coords)
          if np.all(coords[1:] < coords[:-1]):
              if np.isscalar(ind):
                  ind = ncoords - ind - 1
              elif isinstance(ind, slice):
                  start = (
                      None if ind.stop is None else ncoords - ind.stop
                  )
                  stop = (
                      None if ind.start is None else ncoords - ind.start
                  )
                  ind = slice(start, stop, ind.step)
              elif (
                  isinstance(ind, np.ndarray) and ind.dtype.kind == "b"
              ):
                  ind = ind[::-1]
              elif isinstance(ind, (np.ndarray, list)):
                  ind = [ncoords - i - 1 for i in ind]
          if isinstance(ind, list):
              ind = np.array(ind)
          if isinstance(ind, np.ndarray) and ind.dtype.kind == "b":
              ind = np.where(ind)[0]
          adjusted_indices.append(ind)
  
      isel = dict(zip(slice_dims, adjusted_indices))
      all_scalar = all(map(np.isscalar, indices))
      if (
          all_scalar
          and len(indices) == len(kdims)
          and len(dataset.vdims) == 1
      ):
          return (
              dataset.data[dataset.vdims[0].name]
              .isel(**isel)
              .values.item()
          )
  
      # Detect if the indexing is selecting samples or slicing the array
      sampled = all(
          isinstance(ind, np.ndarray) and ind.dtype.kind != "b"
          for ind in adjusted_indices
      ) and len(indices) == len(kdims)
      if sampled or (all_scalar and len(indices) == len(kdims)):
          import xarray as xr
  
          if cls.packed(dataset):
              selected = dataset.data.isel(
                  {k: xr.DataArray(v) for k, v in isel.items()}
              )
              df = selected.to_dataframe("vdims")[["vdims"]].T
              vdims = [vd.name for vd in dataset.vdims]
              return df.rename(
                  columns={i: d for i, d in enumerate(vdims)}
              )[vdims]
          if all_scalar:
              isel = {k: [v] for k, v in isel.items()}
          selected = dataset.data.isel(
              {k: xr.DataArray(v) for k, v in isel.items()}
          )
          return selected.to_dataframe().reset_index()
      else:
          return dataset.data.isel(**isel)
  
imports: import sys
  import types
  import numpy
  import pandas
  from ..None import util
  from ..dimension import Dimension, asdim, dimension_name
  from ..element import Element
  from ..ndmapping import NdMapping, item_check, sorted_context
  from .grid import GridInterface
  from .interface import DataError, Interface
  from .util import dask_array_module, finite_range
label_desc: Use image node_id 17 for calling the XArrayInterface obj's underlying member method code with example usage: obj.ndloc(cls, dataset, indices) and returns: dataset, selected, dataset, df