code: def _to_on_fn(on: Optional[str]):
      if on is None:
          return lambda r: r
      elif isinstance(on, str):
          return lambda r: r[on]
      else:
          return on
  
imports: import math
  from typing import TYPE_CHECKING, Callable, List, Optional, Union
  from ray.data._internal.null_aggregate import _null_wrap_accumulate_block, _null_wrap_accumulate_row, _null_wrap_finalize, _null_wrap_init, _null_wrap_merge
  from ray.data._internal.sort import SortKey
  from ray.data.block import AggType, Block, BlockAccessor, KeyType, T, U
  from ray.util.annotations import PublicAPI
label_desc: Use image node_id 1 for calling a global function with example usage: _to_on_fn(on) and returns: function, function, on