code: def _bins_to_cuts(
      x,
      bins,
      right=True,
      labels=None,
      precision=3,
      include_lowest=False,
      dtype=None,
      duplicates="raise",
  ):
      if duplicates not in ["raise", "drop"]:
          raise ValueError(
              "invalid value for 'duplicates' parameter, "
              "valid options are: raise, drop"
          )
  
      if isinstance(bins, IntervalIndex):
          # we have a fast-path here
          ids = bins.get_indexer(x)
          result = algos.take_nd(bins, ids)
          result = Categorical(result, categories=bins, ordered=True)
          return result, bins
  
      unique_bins = algos.unique(bins)
      if len(unique_bins) < len(bins) and len(bins) != 2:
          if duplicates == "raise":
              raise ValueError(
                  "Bin edges must be unique: {bins!r}.\nYou "
                  "can drop duplicate edges by setting "
                  "the 'duplicates' kwarg".format(bins=bins)
              )
          else:
              bins = unique_bins
  
      side = "left" if right else "right"
      ids = ensure_int64(bins.searchsorted(x, side=side))
  
      if include_lowest:
          ids[x == bins[0]] = 1
  
      na_mask = isna(x) | (ids == len(bins)) | (ids == 0)
      has_nas = na_mask.any()
  
      if labels is not False:
          if labels is None:
              labels = _format_labels(
                  bins,
                  precision,
                  right=right,
                  include_lowest=include_lowest,
                  dtype=dtype,
              )
          else:
              if len(labels) != len(bins) - 1:
                  raise ValueError(
                      "Bin labels must be one fewer than "
                      "the number of bin edges"
                  )
          if not is_categorical_dtype(labels):
              labels = Categorical(
                  labels, categories=labels, ordered=True
              )
  
          np.putmask(ids, na_mask, 0)
          result = algos.take_nd(labels, ids - 1)
  
      else:
          result = ids - 1
          if has_nas:
              result = result.astype(np.float64)
              np.putmask(result, na_mask, np.nan)
  
      return result, bins
  
file_path: catboost/contrib/python/pandas/py2/pandas/core/reshape/tile.py
imports: from functools import partial
  import numpy
  from pandas._libs.lib import infer_dtype
  from pandas.core.dtypes.common import _NS_DTYPE, ensure_int64, is_categorical_dtype, is_datetime64_dtype, is_datetime64tz_dtype, is_datetime_or_timedelta_dtype, is_integer, is_scalar, is_timedelta64_dtype
  from pandas.core.dtypes.missing import isna
  from pandas import Categorical, Index, Interval, IntervalIndex, Series, Timedelta, Timestamp, to_datetime, to_timedelta
  import pandas.core.algorithms
  import pandas.core.nanops
label_desc: Use image node_id 3 for calling a global function with example usage: _bins_to_cuts(x, bins, right, labels, precision, include_lowest, dtype, duplicates) and returns: result,  bins, result,  bins