code: def boundary_slice(
      df,
      start,
      stop,
      right_boundary=True,
      left_boundary=True,
      kind=None,
  ):
      """Index slice start/stop. Can switch include/exclude boundaries.
  
      Examples
      --------
      >>> df = pd.DataFrame({'x': [10, 20, 30, 40, 50]}, index=[1, 2, 2, 3, 4])
      >>> boundary_slice(df, 2, None)
          x
      2  20
      2  30
      3  40
      4  50
      >>> boundary_slice(df, 1, 3)
          x
      1  10
      2  20
      2  30
      3  40
      >>> boundary_slice(df, 1, 3, right_boundary=False)
          x
      1  10
      2  20
      2  30
  
      Empty input DataFrames are returned
  
      >>> df_empty = pd.DataFrame()
      >>> boundary_slice(df_empty, 1, 3)
      Empty DataFrame
      Columns: []
      Index: []
      """
      if len(df.index) == 0:
          return df
  
      if PANDAS_GE_131:
          if kind is not None:
              warnings.warn(
                  "The `kind` argument is no longer used/supported. "
                  "It will be dropped in a future release.",
                  category=FutureWarning,
              )
          kind_opts = {}
          kind = "loc"
      else:
          kind = kind or "loc"
          kind_opts = {"kind": kind}
  
      if kind == "loc" and not df.index.is_monotonic_increasing:
          # Pandas treats missing keys differently for label-slicing
          # on monotonic vs. non-monotonic indexes
          # If the index is monotonic, `df.loc[start:stop]` is fine.
          # If it's not, `df.loc[start:stop]` raises when `start` is missing
          if start is not None:
              if left_boundary:
                  df = df[df.index >= start]
              else:
                  df = df[df.index > start]
          if stop is not None:
              if right_boundary:
                  df = df[df.index <= stop]
              else:
                  df = df[df.index < stop]
          return df
  
      result = getattr(df, kind)[start:stop]
      if not right_boundary and stop is not None:
          right_index = result.index.get_slice_bound(
              stop, "left", **kind_opts
          )
          result = result.iloc[:right_index]
      if not left_boundary and start is not None:
          left_index = result.index.get_slice_bound(
              start, "right", **kind_opts
          )
          result = result.iloc[left_index:]
      return result
  
imports: from __future__ import annotations
  import warnings
  from functools import partial
  import numpy
  import pandas
  from pandas.api.types import is_extension_array_dtype
  from pandas.errors import PerformanceWarning
  from tlz import partition
  from dask.dataframe._compat import PANDAS_GE_131, PANDAS_GE_140, PANDAS_GE_200, check_apply_dataframe_deprecation, check_applymap_dataframe_deprecation, check_convert_dtype_deprecation, check_observed_deprecation
  from dask.dataframe.dispatch import concat, concat_dispatch, group_split_dispatch, hash_object_dispatch, is_categorical_dtype, is_categorical_dtype_dispatch, tolist, tolist_dispatch, union_categoricals
  from dask.dataframe.utils import is_dataframe_like, is_index_like, is_series_like
label_desc: Use image node_id 6 for calling a global function with example usage: boundary_slice(df, start, stop, right_boundary, left_boundary, kind) and returns: result, df, df