code: def pair_partitions(L, R):
      """Returns which partitions to pair for the merge_asof algorithm and the
      bounds on which to split them up
      """
      result = []
  
      n, m = len(L) - 1, len(R) - 1
      i, j = 0, -1
      while j + 1 < m and R[j + 1] <= L[i]:
          j += 1
      J = []
      while i < n:
          partition = max(0, min(m - 1, j))
          lower = R[j] if j >= 0 and R[j] > L[i] else None
          upper = (
              R[j + 1]
              if j + 1 < m
              and (
                  R[j + 1] < L[i + 1]
                  or R[j + 1] == L[i + 1]
                  and i == n - 1
              )
              else None
          )
  
          J.append((partition, lower, upper))
  
          i1 = (
              i + 1
              if j + 1 == m or (i + 1 < n and R[j + 1] >= L[i + 1])
              else i
          )
          j1 = (
              j + 1
              if i + 1 == n or (j + 1 < m and L[i + 1] >= R[j + 1])
              else j
          )
          if i1 > i:
              result.append(J)
              J = []
          elif i == n - 1 and R[j1] > L[n]:
              result.append(J)
              break
          i, j = i1, j1
  
      return result
  
imports: from __future__ import annotations
  import math
  import pickle
  import warnings
  from functools import partial, wraps
  import numpy
  import pandas
  from pandas.api.types import is_dtype_equal
  from tlz import merge_sorted, unique
  from dask.base import is_dask_collection, tokenize
  from dask.dataframe import methods
  from dask.dataframe.core import DataFrame, Index, Series, _concat, _deprecated_kwarg, _Frame, _maybe_from_pandas, is_broadcastable, map_partitions, new_dd_object, prefix_reduction, suffix_reduction
  from dask.dataframe.dispatch import group_split_dispatch, hash_object_dispatch
  from dask.dataframe.io import from_pandas
  from dask.dataframe.shuffle import partitioning_index, rearrange_by_divisions, shuffle, shuffle_group
  from dask.dataframe.utils import asciitable, check_meta, is_dataframe_like, is_series_like, make_meta, strip_unknown_categories
  from dask.highlevelgraph import HighLevelGraph
  from dask.layers import BroadcastJoinLayer
  from dask.utils import M, apply, get_default_shuffle_method
label_desc: Use image node_id 16 for calling a global function with example usage: pair_partitions(L, R) and returns: result