nodes: 0, module; 1, function_definition; 2, function_name:difference; 3, parameters; 4, block; 5, identifier:self; 6, identifier:other; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, if_statement; 19, return_statement; 20, identifier:sort; 21, None; 22, comment:"""
          Return a new Index with elements from the index that are not in
          `other`.
  
          This is the set difference of two Index objects.
  
          Parameters
          ----------
          other : Index or array-like
          sort : False or None, default None
              Whether to sort the resulting index. By default, the
              values are attempted to be sorted, but any TypeError from
              incomparable elements is caught by pandas.
  
              * None : Attempt to sort the result, but catch any TypeErrors
                from comparing incomparable elements.
              * False : Do not sort the result.
  
              .. versionadded:: 0.24.0
  
              .. versionchanged:: 0.24.1
  
                 Changed the default value from ``True`` to ``None``
                 (without change in behaviour).
  
          Returns
          -------
          difference : Index
  
          Examples
          --------
  
          >>> idx1 = pd.Index([2, 1, 3, 4])
          >>> idx2 = pd.Index([3, 4, 5, 6])
          >>> idx1.difference(idx2)
          Int64Index([1, 2], dtype='int64')
          >>> idx1.difference(idx2, sort=False)
          Int64Index([2, 1], dtype='int64')
          """; 23, call; 24, call; 25, call; 26, comment:# pass an empty np.ndarray with the appropriate dtype; 27, block; 28, assignment; 29, assignment; 30, assignment; 31, assignment; 32, assignment; 33, assignment; 34, comparison_operator:sort is None; 35, block; 36, call; 37, attribute; 38, argument_list; 39, attribute; 40, argument_list; 41, attribute; 42, argument_list; 43, return_statement; 44, pattern_list; 45, call; 46, identifier:this; 47, call; 48, identifier:indexer; 49, call; 50, identifier:indexer; 51, call; 52, identifier:label_diff; 53, call; 54, identifier:the_diff; 55, call; 56, identifier:sort; 57, None; 58, try_statement; 59, attribute; 60, argument_list; 61, identifier:self; 62, identifier:_validate_sort_keyword; 63, identifier:sort; 64, identifier:self; 65, identifier:_assert_can_do_setop; 66, identifier:other; 67, identifier:self; 68, identifier:equals; 69, identifier:other; 70, call; 71, identifier:other; 72, identifier:result_name; 73, attribute; 74, argument_list; 75, attribute; 76, argument_list; 77, attribute; 78, argument_list; 79, attribute; 80, argument_list; 81, attribute; 82, argument_list; 83, attribute; 84, argument_list; 85, block; 86, except_clause; 87, identifier:this; 88, identifier:_shallow_copy; 89, identifier:the_diff; 90, keyword_argument; 91, keyword_argument; 92, attribute; 93, argument_list; 94, identifier:self; 95, identifier:_convert_can_do_setop; 96, identifier:other; 97, identifier:self; 98, identifier:_get_unique_index; 99, identifier:this; 100, identifier:get_indexer; 101, identifier:other; 102, identifier:indexer; 103, identifier:take; 104, subscript; 105, identifier:np; 106, identifier:setdiff1d; 107, call; 108, identifier:indexer; 109, keyword_argument; 110, attribute; 111, identifier:take; 112, identifier:label_diff; 113, expression_statement; 114, identifier:TypeError; 115, block; 116, identifier:name; 117, identifier:result_name; 118, identifier:freq; 119, None; 120, identifier:self; 121, identifier:_shallow_copy; 122, subscript; 123, call; 124, integer:0; 125, attribute; 126, argument_list; 127, identifier:assume_unique; 128, True; 129, identifier:this; 130, identifier:values; 131, assignment; 132, pass_statement; 133, attribute; 134, slice; 135, attribute; 136, argument_list; 137, identifier:np; 138, identifier:arange; 139, attribute; 140, identifier:the_diff; 141, call; 142, identifier:self; 143, identifier:_data; 144, integer:0; 145, parenthesized_expression; 146, identifier:nonzero; 147, identifier:this; 148, identifier:size; 149, attribute; 150, argument_list; 151, comparison_operator:indexer != -1; 152, identifier:sorting; 153, identifier:safe_sort; 154, identifier:the_diff; 155, identifier:indexer; 156, unary_operator; 157, integer:1
code: def difference(self, other, sort=None):
          """
          Return a new Index with elements from the index that are not in
          `other`.
  
          This is the set difference of two Index objects.
  
          Parameters
          ----------
          other : Index or array-like
          sort : False or None, default None
              Whether to sort the resulting index. By default, the
              values are attempted to be sorted, but any TypeError from
              incomparable elements is caught by pandas.
  
              * None : Attempt to sort the result, but catch any TypeErrors
                from comparing incomparable elements.
              * False : Do not sort the result.
  
              .. versionadded:: 0.24.0
  
              .. versionchanged:: 0.24.1
  
                 Changed the default value from ``True`` to ``None``
                 (without change in behaviour).
  
          Returns
          -------
          difference : Index
  
          Examples
          --------
  
          >>> idx1 = pd.Index([2, 1, 3, 4])
          >>> idx2 = pd.Index([3, 4, 5, 6])
          >>> idx1.difference(idx2)
          Int64Index([1, 2], dtype='int64')
          >>> idx1.difference(idx2, sort=False)
          Int64Index([2, 1], dtype='int64')
          """
          self._validate_sort_keyword(sort)
          self._assert_can_do_setop(other)
  
          if self.equals(other):
              # pass an empty np.ndarray with the appropriate dtype
              return self._shallow_copy(self._data[:0])
  
          other, result_name = self._convert_can_do_setop(other)
  
          this = self._get_unique_index()
  
          indexer = this.get_indexer(other)
          indexer = indexer.take((indexer != -1).nonzero()[0])
  
          label_diff = np.setdiff1d(np.arange(this.size), indexer,
                                    assume_unique=True)
          the_diff = this.values.take(label_diff)
          if sort is None:
              try:
                  the_diff = sorting.safe_sort(the_diff)
              except TypeError:
                  pass
  
          return this._shallow_copy(the_diff, name=result_name, freq=None)