nodes: 0, module; 1, function_definition; 2, function_name:cut; 3, parameters; 4, block; 5, identifier:x; 6, identifier:bins; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, expression_statement; 14, comment:# NOTE: this binning code is changed a bit from histogram for var(x) == 0; 15, comment:# for handling the cut for datetime and timedelta objects; 16, expression_statement; 17, expression_statement; 18, if_statement; 19, expression_statement; 20, return_statement; 21, identifier:right; 22, True; 23, identifier:labels; 24, None; 25, identifier:retbins; 26, False; 27, identifier:precision; 28, integer:3; 29, identifier:include_lowest; 30, False; 31, identifier:duplicates; 32, string; 33, comment:"""
      Bin values into discrete intervals.
  
      Use `cut` when you need to segment and sort data values into bins. This
      function is also useful for going from a continuous variable to a
      categorical variable. For example, `cut` could convert ages to groups of
      age ranges. Supports binning into an equal number of bins, or a
      pre-specified array of bins.
  
      Parameters
      ----------
      x : array-like
          The input array to be binned. Must be 1-dimensional.
      bins : int, sequence of scalars, or IntervalIndex
          The criteria to bin by.
  
          * int : Defines the number of equal-width bins in the range of `x`. The
            range of `x` is extended by .1% on each side to include the minimum
            and maximum values of `x`.
          * sequence of scalars : Defines the bin edges allowing for non-uniform
            width. No extension of the range of `x` is done.
          * IntervalIndex : Defines the exact bins to be used. Note that
            IntervalIndex for `bins` must be non-overlapping.
  
      right : bool, default True
          Indicates whether `bins` includes the rightmost edge or not. If
          ``right == True`` (the default), then the `bins` ``[1, 2, 3, 4]``
          indicate (1,2], (2,3], (3,4]. This argument is ignored when
          `bins` is an IntervalIndex.
      labels : array or bool, optional
          Specifies the labels for the returned bins. Must be the same length as
          the resulting bins. If False, returns only integer indicators of the
          bins. This affects the type of the output container (see below).
          This argument is ignored when `bins` is an IntervalIndex.
      retbins : bool, default False
          Whether to return the bins or not. Useful when bins is provided
          as a scalar.
      precision : int, default 3
          The precision at which to store and display the bins labels.
      include_lowest : bool, default False
          Whether the first interval should be left-inclusive or not.
      duplicates : {default 'raise', 'drop'}, optional
          If bin edges are not unique, raise ValueError or drop non-uniques.
  
          .. versionadded:: 0.23.0
  
      Returns
      -------
      out : Categorical, Series, or ndarray
          An array-like object representing the respective bin for each value
          of `x`. The type depends on the value of `labels`.
  
          * True (default) : returns a Series for Series `x` or a
            Categorical for all other inputs. The values stored within
            are Interval dtype.
  
          * sequence of scalars : returns a Series for Series `x` or a
            Categorical for all other inputs. The values stored within
            are whatever the type in the sequence is.
  
          * False : returns an ndarray of integers.
  
      bins : numpy.ndarray or IntervalIndex.
          The computed or specified bins. Only returned when `retbins=True`.
          For scalar or sequence `bins`, this is an ndarray with the computed
          bins. If set `duplicates=drop`, `bins` will drop non-unique bin. For
          an IntervalIndex `bins`, this is equal to `bins`.
  
      See Also
      --------
      qcut : Discretize variable into equal-sized buckets based on rank
          or based on sample quantiles.
      Categorical : Array type for storing data that come from a
          fixed set of values.
      Series : One-dimensional array with axis labels (including time series).
      IntervalIndex : Immutable Index implementing an ordered, sliceable set.
  
      Notes
      -----
      Any NA values will be NA in the result. Out of bounds values will be NA in
      the resulting Series or Categorical object.
  
      Examples
      --------
      Discretize into three equal-sized bins.
  
      >>> pd.cut(np.array([1, 7, 5, 4, 6, 3]), 3)
      ... # doctest: +ELLIPSIS
      [(0.994, 3.0], (5.0, 7.0], (3.0, 5.0], (3.0, 5.0], (5.0, 7.0], ...
      Categories (3, interval[float64]): [(0.994, 3.0] < (3.0, 5.0] ...
  
      >>> pd.cut(np.array([1, 7, 5, 4, 6, 3]), 3, retbins=True)
      ... # doctest: +ELLIPSIS
      ([(0.994, 3.0], (5.0, 7.0], (3.0, 5.0], (3.0, 5.0], (5.0, 7.0], ...
      Categories (3, interval[float64]): [(0.994, 3.0] < (3.0, 5.0] ...
      array([0.994, 3.   , 5.   , 7.   ]))
  
      Discovers the same bins, but assign them specific labels. Notice that
      the returned Categorical's categories are `labels` and is ordered.
  
      >>> pd.cut(np.array([1, 7, 5, 4, 6, 3]),
      ...        3, labels=["bad", "medium", "good"])
      [bad, good, medium, medium, good, bad]
      Categories (3, object): [bad < medium < good]
  
      ``labels=False`` implies you just want the bins back.
  
      >>> pd.cut([0, 1, 1, 2], bins=4, labels=False)
      array([0, 1, 1, 3])
  
      Passing a Series as an input returns a Series with categorical dtype:
  
      >>> s = pd.Series(np.array([2, 4, 6, 8, 10]),
      ...               index=['a', 'b', 'c', 'd', 'e'])
      >>> pd.cut(s, 3)
      ... # doctest: +ELLIPSIS
      a    (1.992, 4.667]
      b    (1.992, 4.667]
      c    (4.667, 7.333]
      d     (7.333, 10.0]
      e     (7.333, 10.0]
      dtype: category
      Categories (3, interval[float64]): [(1.992, 4.667] < (4.667, ...
  
      Passing a Series as an input returns a Series with mapping value.
      It is used to map numerically to intervals based on bins.
  
      >>> s = pd.Series(np.array([2, 4, 6, 8, 10]),
      ...               index=['a', 'b', 'c', 'd', 'e'])
      >>> pd.cut(s, [0, 2, 4, 6, 8, 10], labels=False, retbins=True, right=False)
      ... # doctest: +ELLIPSIS
      (a    0.0
       b    1.0
       c    2.0
       d    3.0
       e    4.0
       dtype: float64, array([0, 2, 4, 6, 8]))
  
      Use `drop` optional when bins is not unique
  
      >>> pd.cut(s, [0, 2, 4, 6, 10, 10], labels=False, retbins=True,
      ...        right=False, duplicates='drop')
      ... # doctest: +ELLIPSIS
      (a    0.0
       b    1.0
       c    2.0
       d    3.0
       e    3.0
       dtype: float64, array([0, 2, 4, 6, 8]))
  
      Passing an IntervalIndex for `bins` results in those categories exactly.
      Notice that values not covered by the IntervalIndex are set to NaN. 0
      is to the left of the first bin (which is closed on the right), and 1.5
      falls between two bins.
  
      >>> bins = pd.IntervalIndex.from_tuples([(0, 1), (2, 3), (4, 5)])
      >>> pd.cut([0, 0.5, 1.5, 2.5, 4.5], bins)
      [NaN, (0, 1], NaN, (2, 3], (4, 5]]
      Categories (3, interval[int64]): [(0, 1] < (2, 3] < (4, 5]]
      """; 34, assignment; 35, assignment; 36, not_operator; 37, block; 38, elif_clause; 39, else_clause; 40, assignment; 41, call; 42, string_content:raise; 43, pattern_list; 44, call; 45, pattern_list; 46, call; 47, call; 48, if_statement; 49, try_statement; 50, if_statement; 51, expression_statement; 52, expression_statement; 53, if_statement; 54, call; 55, block; 56, block; 57, pattern_list; 58, call; 59, identifier:_postprocess_for_cut; 60, argument_list; 61, identifier:x_is_series; 62, identifier:series_index; 63, identifier:name; 64, identifier:x; 65, identifier:_preprocess_for_cut; 66, argument_list; 67, identifier:x; 68, identifier:dtype; 69, identifier:_coerce_to_type; 70, argument_list; 71, attribute; 72, argument_list; 73, boolean_operator; 74, block; 75, comment:# for array-like; 76, block; 77, except_clause; 78, comparison_operator:sz == 0; 79, block; 80, assignment; 81, assignment; 82, boolean_operator; 83, comment:# GH 24314; 84, block; 85, elif_clause; 86, else_clause; 87, identifier:isinstance; 88, argument_list; 89, if_statement; 90, if_statement; 91, expression_statement; 92, comment:# GH 26045: cast to float64 to avoid an overflow; 93, if_statement; 94, identifier:fac; 95, identifier:bins; 96, identifier:_bins_to_cuts; 97, argument_list; 98, identifier:fac; 99, identifier:bins; 100, identifier:retbins; 101, identifier:x_is_series; 102, identifier:series_index; 103, identifier:name; 104, identifier:dtype; 105, identifier:x; 106, identifier:x; 107, identifier:np; 108, identifier:iterable; 109, identifier:bins; 110, call; 111, comparison_operator:bins < 1; 112, raise_statement; 113, expression_statement; 114, identifier:AttributeError; 115, block; 116, identifier:sz; 117, integer:0; 118, raise_statement; 119, identifier:rng; 120, tuple; 121, pattern_list; 122, list_comprehension; 123, call; 124, call; 125, raise_statement; 126, comparison_operator:mn == mx; 127, comment:# adjust end points before binning; 128, block; 129, comment:# adjust end points after binning; 130, block; 131, identifier:bins; 132, identifier:IntervalIndex; 133, attribute; 134, block; 135, call; 136, block; 137, else_clause; 138, assignment; 139, call; 140, block; 141, identifier:x; 142, identifier:bins; 143, keyword_argument; 144, keyword_argument; 145, keyword_argument; 146, keyword_argument; 147, keyword_argument; 148, keyword_argument; 149, identifier:is_scalar; 150, argument_list; 151, identifier:bins; 152, integer:1; 153, call; 154, assignment; 155, expression_statement; 156, expression_statement; 157, call; 158, call; 159, call; 160, identifier:mn; 161, identifier:mx; 162, binary_operator:mi + 0.0; 163, for_in_clause; 164, attribute; 165, argument_list; 166, attribute; 167, argument_list; 168, call; 169, identifier:mn; 170, identifier:mx; 171, expression_statement; 172, expression_statement; 173, expression_statement; 174, expression_statement; 175, expression_statement; 176, comment:# 0.1% of the range; 177, if_statement; 178, identifier:bins; 179, identifier:is_overlapping; 180, raise_statement; 181, identifier:is_datetime64tz_dtype; 182, argument_list; 183, expression_statement; 184, block; 185, identifier:bins; 186, call; 187, attribute; 188, argument_list; 189, raise_statement; 190, identifier:right; 191, identifier:right; 192, identifier:labels; 193, identifier:labels; 194, identifier:precision; 195, identifier:precision; 196, identifier:include_lowest; 197, identifier:include_lowest; 198, identifier:dtype; 199, identifier:dtype; 200, identifier:duplicates; 201, identifier:duplicates; 202, identifier:bins; 203, identifier:ValueError; 204, argument_list; 205, identifier:sz; 206, attribute; 207, assignment; 208, assignment; 209, identifier:ValueError; 210, argument_list; 211, attribute; 212, argument_list; 213, attribute; 214, argument_list; 215, identifier:mi; 216, float:0.0; 217, identifier:mi; 218, identifier:rng; 219, identifier:np; 220, identifier:isinf; 221, identifier:mn; 222, identifier:np; 223, identifier:isinf; 224, identifier:mx; 225, identifier:ValueError; 226, argument_list; 227, augmented_assignment; 228, augmented_assignment; 229, assignment; 230, assignment; 231, assignment; 232, identifier:right; 233, block; 234, else_clause; 235, call; 236, identifier:bins; 237, assignment; 238, expression_statement; 239, identifier:_convert_bin_to_numeric_type; 240, argument_list; 241, parenthesized_expression; 242, identifier:any; 243, call; 244, string:"`bins` should be a positive integer."; 245, identifier:x; 246, identifier:size; 247, identifier:x; 248, call; 249, identifier:sz; 250, attribute; 251, string; 252, identifier:nanops; 253, identifier:nanmin; 254, identifier:x; 255, identifier:nanops; 256, identifier:nanmax; 257, identifier:x; 258, concatenated_string; 259, identifier:mn; 260, conditional_expression:.001 * abs(mn) if mn != 0 else .001; 261, identifier:mx; 262, conditional_expression:.001 * abs(mx) if mx != 0 else .001; 263, identifier:bins; 264, call; 265, identifier:bins; 266, call; 267, identifier:adj; 268, binary_operator:(mx - mn) * 0.001; 269, expression_statement; 270, block; 271, identifier:ValueError; 272, argument_list; 273, identifier:bins; 274, call; 275, assignment; 276, identifier:bins; 277, identifier:dtype; 278, comparison_operator:np.diff(bins.astype('float64')) < 0; 279, identifier:ValueError; 280, argument_list; 281, attribute; 282, argument_list; 283, identifier:x; 284, identifier:size; 285, string_content:Cannot cut empty array; 286, string; 287, string; 288, binary_operator:.001 * abs(mn); 289, comparison_operator:mn != 0; 290, float:.001; 291, binary_operator:.001 * abs(mx); 292, comparison_operator:mx != 0; 293, float:.001; 294, attribute; 295, argument_list; 296, attribute; 297, argument_list; 298, parenthesized_expression; 299, float:0.001; 300, augmented_assignment; 301, expression_statement; 302, string; 303, attribute; 304, argument_list; 305, identifier:bins; 306, call; 307, call; 308, integer:0; 309, string; 310, identifier:np; 311, identifier:asarray; 312, identifier:x; 313, string_content:cannot specify integer `bins` when input data; 314, string_content:contains infinity; 315, float:.001; 316, call; 317, identifier:mn; 318, integer:0; 319, float:.001; 320, call; 321, identifier:mx; 322, integer:0; 323, identifier:np; 324, identifier:linspace; 325, identifier:mn; 326, identifier:mx; 327, binary_operator:bins + 1; 328, keyword_argument; 329, identifier:np; 330, identifier:linspace; 331, identifier:mn; 332, identifier:mx; 333, binary_operator:bins + 1; 334, keyword_argument; 335, binary_operator:mx - mn; 336, subscript; 337, identifier:adj; 338, augmented_assignment; 339, string_content:Overlapping IntervalIndex is not accepted.; 340, identifier:np; 341, identifier:asarray; 342, identifier:bins; 343, keyword_argument; 344, attribute; 345, argument_list; 346, attribute; 347, argument_list; 348, string_content:bins must increase monotonically.; 349, identifier:abs; 350, argument_list; 351, identifier:abs; 352, argument_list; 353, identifier:bins; 354, integer:1; 355, identifier:endpoint; 356, True; 357, identifier:bins; 358, integer:1; 359, identifier:endpoint; 360, True; 361, identifier:mx; 362, identifier:mn; 363, identifier:bins; 364, integer:0; 365, subscript; 366, identifier:adj; 367, identifier:dtype; 368, identifier:_NS_DTYPE; 369, identifier:np; 370, identifier:asarray; 371, identifier:bins; 372, identifier:np; 373, identifier:diff; 374, call; 375, identifier:mn; 376, identifier:mx; 377, identifier:bins; 378, unary_operator; 379, attribute; 380, argument_list; 381, integer:1; 382, identifier:bins; 383, identifier:astype; 384, string; 385, string_content:float64
code: def cut(x, bins, right=True, labels=None, retbins=False, precision=3,
          include_lowest=False, duplicates='raise'):
      """
      Bin values into discrete intervals.
  
      Use `cut` when you need to segment and sort data values into bins. This
      function is also useful for going from a continuous variable to a
      categorical variable. For example, `cut` could convert ages to groups of
      age ranges. Supports binning into an equal number of bins, or a
      pre-specified array of bins.
  
      Parameters
      ----------
      x : array-like
          The input array to be binned. Must be 1-dimensional.
      bins : int, sequence of scalars, or IntervalIndex
          The criteria to bin by.
  
          * int : Defines the number of equal-width bins in the range of `x`. The
            range of `x` is extended by .1% on each side to include the minimum
            and maximum values of `x`.
          * sequence of scalars : Defines the bin edges allowing for non-uniform
            width. No extension of the range of `x` is done.
          * IntervalIndex : Defines the exact bins to be used. Note that
            IntervalIndex for `bins` must be non-overlapping.
  
      right : bool, default True
          Indicates whether `bins` includes the rightmost edge or not. If
          ``right == True`` (the default), then the `bins` ``[1, 2, 3, 4]``
          indicate (1,2], (2,3], (3,4]. This argument is ignored when
          `bins` is an IntervalIndex.
      labels : array or bool, optional
          Specifies the labels for the returned bins. Must be the same length as
          the resulting bins. If False, returns only integer indicators of the
          bins. This affects the type of the output container (see below).
          This argument is ignored when `bins` is an IntervalIndex.
      retbins : bool, default False
          Whether to return the bins or not. Useful when bins is provided
          as a scalar.
      precision : int, default 3
          The precision at which to store and display the bins labels.
      include_lowest : bool, default False
          Whether the first interval should be left-inclusive or not.
      duplicates : {default 'raise', 'drop'}, optional
          If bin edges are not unique, raise ValueError or drop non-uniques.
  
          .. versionadded:: 0.23.0
  
      Returns
      -------
      out : Categorical, Series, or ndarray
          An array-like object representing the respective bin for each value
          of `x`. The type depends on the value of `labels`.
  
          * True (default) : returns a Series for Series `x` or a
            Categorical for all other inputs. The values stored within
            are Interval dtype.
  
          * sequence of scalars : returns a Series for Series `x` or a
            Categorical for all other inputs. The values stored within
            are whatever the type in the sequence is.
  
          * False : returns an ndarray of integers.
  
      bins : numpy.ndarray or IntervalIndex.
          The computed or specified bins. Only returned when `retbins=True`.
          For scalar or sequence `bins`, this is an ndarray with the computed
          bins. If set `duplicates=drop`, `bins` will drop non-unique bin. For
          an IntervalIndex `bins`, this is equal to `bins`.
  
      See Also
      --------
      qcut : Discretize variable into equal-sized buckets based on rank
          or based on sample quantiles.
      Categorical : Array type for storing data that come from a
          fixed set of values.
      Series : One-dimensional array with axis labels (including time series).
      IntervalIndex : Immutable Index implementing an ordered, sliceable set.
  
      Notes
      -----
      Any NA values will be NA in the result. Out of bounds values will be NA in
      the resulting Series or Categorical object.
  
      Examples
      --------
      Discretize into three equal-sized bins.
  
      >>> pd.cut(np.array([1, 7, 5, 4, 6, 3]), 3)
      ... # doctest: +ELLIPSIS
      [(0.994, 3.0], (5.0, 7.0], (3.0, 5.0], (3.0, 5.0], (5.0, 7.0], ...
      Categories (3, interval[float64]): [(0.994, 3.0] < (3.0, 5.0] ...
  
      >>> pd.cut(np.array([1, 7, 5, 4, 6, 3]), 3, retbins=True)
      ... # doctest: +ELLIPSIS
      ([(0.994, 3.0], (5.0, 7.0], (3.0, 5.0], (3.0, 5.0], (5.0, 7.0], ...
      Categories (3, interval[float64]): [(0.994, 3.0] < (3.0, 5.0] ...
      array([0.994, 3.   , 5.   , 7.   ]))
  
      Discovers the same bins, but assign them specific labels. Notice that
      the returned Categorical's categories are `labels` and is ordered.
  
      >>> pd.cut(np.array([1, 7, 5, 4, 6, 3]),
      ...        3, labels=["bad", "medium", "good"])
      [bad, good, medium, medium, good, bad]
      Categories (3, object): [bad < medium < good]
  
      ``labels=False`` implies you just want the bins back.
  
      >>> pd.cut([0, 1, 1, 2], bins=4, labels=False)
      array([0, 1, 1, 3])
  
      Passing a Series as an input returns a Series with categorical dtype:
  
      >>> s = pd.Series(np.array([2, 4, 6, 8, 10]),
      ...               index=['a', 'b', 'c', 'd', 'e'])
      >>> pd.cut(s, 3)
      ... # doctest: +ELLIPSIS
      a    (1.992, 4.667]
      b    (1.992, 4.667]
      c    (4.667, 7.333]
      d     (7.333, 10.0]
      e     (7.333, 10.0]
      dtype: category
      Categories (3, interval[float64]): [(1.992, 4.667] < (4.667, ...
  
      Passing a Series as an input returns a Series with mapping value.
      It is used to map numerically to intervals based on bins.
  
      >>> s = pd.Series(np.array([2, 4, 6, 8, 10]),
      ...               index=['a', 'b', 'c', 'd', 'e'])
      >>> pd.cut(s, [0, 2, 4, 6, 8, 10], labels=False, retbins=True, right=False)
      ... # doctest: +ELLIPSIS
      (a    0.0
       b    1.0
       c    2.0
       d    3.0
       e    4.0
       dtype: float64, array([0, 2, 4, 6, 8]))
  
      Use `drop` optional when bins is not unique
  
      >>> pd.cut(s, [0, 2, 4, 6, 10, 10], labels=False, retbins=True,
      ...        right=False, duplicates='drop')
      ... # doctest: +ELLIPSIS
      (a    0.0
       b    1.0
       c    2.0
       d    3.0
       e    3.0
       dtype: float64, array([0, 2, 4, 6, 8]))
  
      Passing an IntervalIndex for `bins` results in those categories exactly.
      Notice that values not covered by the IntervalIndex are set to NaN. 0
      is to the left of the first bin (which is closed on the right), and 1.5
      falls between two bins.
  
      >>> bins = pd.IntervalIndex.from_tuples([(0, 1), (2, 3), (4, 5)])
      >>> pd.cut([0, 0.5, 1.5, 2.5, 4.5], bins)
      [NaN, (0, 1], NaN, (2, 3], (4, 5]]
      Categories (3, interval[int64]): [(0, 1] < (2, 3] < (4, 5]]
      """
      # NOTE: this binning code is changed a bit from histogram for var(x) == 0
  
      # for handling the cut for datetime and timedelta objects
      x_is_series, series_index, name, x = _preprocess_for_cut(x)
      x, dtype = _coerce_to_type(x)
  
      if not np.iterable(bins):
          if is_scalar(bins) and bins < 1:
              raise ValueError("`bins` should be a positive integer.")
  
          try:  # for array-like
              sz = x.size
          except AttributeError:
              x = np.asarray(x)
              sz = x.size
  
          if sz == 0:
              raise ValueError('Cannot cut empty array')
  
          rng = (nanops.nanmin(x), nanops.nanmax(x))
          mn, mx = [mi + 0.0 for mi in rng]
  
          if np.isinf(mn) or np.isinf(mx):
              # GH 24314
              raise ValueError('cannot specify integer `bins` when input data '
                               'contains infinity')
          elif mn == mx:  # adjust end points before binning
              mn -= .001 * abs(mn) if mn != 0 else .001
              mx += .001 * abs(mx) if mx != 0 else .001
              bins = np.linspace(mn, mx, bins + 1, endpoint=True)
          else:  # adjust end points after binning
              bins = np.linspace(mn, mx, bins + 1, endpoint=True)
              adj = (mx - mn) * 0.001  # 0.1% of the range
              if right:
                  bins[0] -= adj
              else:
                  bins[-1] += adj
  
      elif isinstance(bins, IntervalIndex):
          if bins.is_overlapping:
              raise ValueError('Overlapping IntervalIndex is not accepted.')
  
      else:
          if is_datetime64tz_dtype(bins):
              bins = np.asarray(bins, dtype=_NS_DTYPE)
          else:
              bins = np.asarray(bins)
          bins = _convert_bin_to_numeric_type(bins, dtype)
  
          # GH 26045: cast to float64 to avoid an overflow
          if (np.diff(bins.astype('float64')) < 0).any():
              raise ValueError('bins must increase monotonically.')
  
      fac, bins = _bins_to_cuts(x, bins, right=right, labels=labels,
                                precision=precision,
                                include_lowest=include_lowest,
                                dtype=dtype,
                                duplicates=duplicates)
  
      return _postprocess_for_cut(fac, bins, retbins, x_is_series,
                                  series_index, name, dtype)