code: def _bypixel_sanitise(source, glyph, agg):
      # Convert 1D xarray DataArrays and DataSets into Dask DataFrames
      if isinstance(source, DataArray) and source.ndim == 1:
          if not source.name:
              source.name = "value"
          source = source.reset_coords()
      if isinstance(source, Dataset) and len(source.dims) == 1:
          columns = list(source.coords.keys()) + list(
              source.data_vars.keys()
          )
          cols_to_keep = _cols_to_keep(columns, glyph, agg)
          source = source.drop_vars(
              [col for col in columns if col not in cols_to_keep]
          )
          source = source.to_dask_dataframe()
  
      if isinstance(source, pd.DataFrame) or (
          cudf and isinstance(source, cudf.DataFrame)
      ):
          # Avoid datashape.Categorical instantiation bottleneck
          # by only retaining the necessary columns:
          # https://github.com/bokeh/datashader/issues/396
          # Preserve column ordering without duplicates
  
          cols_to_keep = _cols_to_keep(source.columns, glyph, agg)
          if len(cols_to_keep) < len(source.columns):
              # If _sindex is set, ensure it is not dropped
              # https://github.com/holoviz/datashader/issues/1121
              sindex = None
              from .glyphs.polygon import PolygonGeom
  
              if isinstance(glyph, PolygonGeom):
                  sindex = getattr(
                      source[glyph.geometry].array, "_sindex", None
                  )
              source = source[cols_to_keep]
              if (
                  sindex is not None
                  and getattr(
                      source[glyph.geometry].array, "_sindex", None
                  )
                  is None
              ):
                  source[glyph.geometry].array._sindex = sindex
          dshape = dshape_from_pandas(source)
      elif isinstance(source, dd.DataFrame):
          dshape, source = dshape_from_dask(source)
      elif isinstance(source, Dataset):
          # Multi-dimensional Dataset
          dshape = dshape_from_xarray_dataset(source)
      else:
          raise ValueError("source must be a pandas or dask DataFrame")
  
      return source, dshape
  
imports: from __future__ import annotations
  from numbers import Number
  from math import log10
  import warnings
  import numpy
  import pandas
  import dask.dataframe
  import dask.array
  from xarray import DataArray, Dataset
  from .utils import Dispatcher, ngjit, calc_res, calc_bbox, orient_array, dshape_from_xarray_dataset
  from .utils import get_indices, dshape_from_pandas, dshape_from_dask
  from .utils import Expr
  from .resampling import resample_2d, resample_2d_distributed
  from .None import reductions
label_desc: Use image node_id 3 for calling a global function with example usage: _bypixel_sanitise(source, glyph, agg) and returns: source,  dshape